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

Chen Liang liach at openjdk.org
Thu Mar 28 16:28:54 UTC 2024


On Wed, 27 Mar 2024 17:36:28 GMT, Liam Miller-Cushon <cushon 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()`?

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

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


More information about the core-libs-dev mailing list