RFR: 8328821: Map.of().entrySet() mutators should throw UnsupportedOperationException [v2]
Liam Miller-Cushon
cushon at openjdk.org
Mon May 27 18:27:20 UTC 2024
On Mon, 27 May 2024 12:18:23 GMT, Chen Liang <liach at openjdk.org> wrote:
>> src/java.base/share/classes/java/util/ImmutableCollections.java line 1323:
>>
>>> 1321: @Override
>>> 1322: public int hashCode() {
>>> 1323: return MapN.this.hashCode();
>>
>> The hash code for a `Set` is defined as the sum of the elements in the `Set` (hash(`null`) == 0). The `Map. Entry` hash code is defined the same way `MapN.this.hashCode` operates so this seems right. It would be nice with a couple of tests that assert this invariant.
>>
>> Perhaps the existing tests already cover this?
>
> Good point, this is currently missing from MOAT in Collections.
>
> Though it can be as simple as one line here:
> https://github.com/openjdk/jdk/blob/891d5aedf12e837c9a9c7cb800fb3affa7430f00/test/jdk/java/util/Collection/MOAT.java#L1329
>
> check(m.hashCode() == m.entrySet().hashCode());
Thanks, I added the suggested assertion.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/18522#discussion_r1616313870
More information about the core-libs-dev
mailing list