JDK 8 RFR 8016252: More defensive HashSet.readObject
Chris Hegarty
chris.hegarty at oracle.com
Tue Oct 8 08:51:13 UTC 2013
On 10/07/2013 10:03 PM, Brian Burkhalter wrote:
> On Oct 7, 2013, at 1:43 PM, Brian Burkhalter wrote:
>
>> On second thought an exception really should be thrown on negative size; will update.
>
> http://cr.openjdk.java.net/~bpb/8016252.2/ updated including a not-very-exciting and perhaps unnecessary test.
This looks much better.
loadfactor and size validation look good, and in line with the original
suggestion in the bug.
For the initial capacity what was originally suggested was to use a
similar technique to that of HashMap.readObject ( to ensure that the
table never needs to be rehashed during load, and ends up being at least
25% full). Snippet from the bug:
int capacity = (int)Math.min(size * Math.min(1 / loadFactor, 4.0f),
HashMap.MAXIMUM_CAPACITY);
I'm curious why you have not taken that suggestion? What you have looks
ok, but it does reply on reasonable capacity and loadfactor values.
I have not looked in any detail at the test, but the file should start
with the copyright/header, and not the import statements.
-Chris.
>
> Brian
>
More information about the core-libs-dev
mailing list