RFR: 8328821: Map.of().entrySet() mutators should throw UnsupportedOperationException

Liam Miller-Cushon cushon at openjdk.org
Thu Mar 28 16:28:54 UTC 2024


On Wed, 27 Mar 2024 21:49:10 GMT, Chen Liang <liach at openjdk.org> wrote:

>> This change overrides mutator methods in the implementation returned by `Map.of().entrySet()` to throw `UnsupportedOperationException`.
>
> src/java.base/share/classes/java/util/ImmutableCollections.java line 1321:
> 
>> 1319:                 }
>> 1320: 
>> 1321:                 // all mutating methods throw UnsupportedOperationException
> 
> Can we change this anonymous class to `return new AbstractImmutableSet<>` and override `hashCode` with `MapN.this.hashCode()`?

Thanks, I tried that out and it looks good based on the test coverage. I have tentatively updated the PR to use that approach.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/18522#discussion_r1542163440


More information about the core-libs-dev mailing list