RFR: 8284780: Need methods to create pre-sized HashSet and LinkedHashSet [v10]

Stuart Marks smarks at openjdk.java.net
Wed May 25 05:45:59 UTC 2022


On Wed, 25 May 2022 03:02:45 GMT, ExE Boss <duke at openjdk.java.net> wrote:

>> XenoAmess has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   add test for newHashSet and newLinkedHashSet
>
> test/jdk/java/util/HashMap/WhiteBoxResizeTest.java line 360:
> 
>> 358:                         throw new RuntimeException(e);
>> 359:                     }
>> 360:                 })
> 
> These probably need a `mapField.setAccessible(true)` call, or a `VarHandle` for the `HashSet.map` field.

Yes, this test fails with IllegalAccessException. Probably it's easiest to use a VarHandle to get private fields, similar to other usage already in this test.

This test case is a bit odd though in that it's supposed to test HashSet and LinkedHashSet but it mostly actually tests HashMap. It creates the Set instance and immediately extracts the HashMap, which is then passed to the actual test, which operates directly on the HashMap. It would be preferable to create a Set; add an element (so that it's properly allocated); and then make assertions over the Set (which involve extracting the HashMap, etc.) It seems like there should be factoring that allows this sort of arrangement to be retrofitted without adding too much complication.

Finally, please add "8284780" to the `@bug` line at the top of this test.

-------------

PR: https://git.openjdk.java.net/jdk/pull/8302


More information about the core-libs-dev mailing list