RFR: 8328821: Map.of().entrySet() mutators should throw UnsupportedOperationException
    Per Minborg 
    pminborg at openjdk.org
       
    Mon May 27 07:27:03 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 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.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/18522#discussion_r1615591889
    
    
More information about the core-libs-dev
mailing list