Re: RFR: 8328821: Map.of().entrySet() mutators should throw UnsupportedOperationException [v2]

2024-05-27 Thread Liam Miller-Cushon
> This change overrides mutator methods in the implementation returned by 
> `Map.of().entrySet()` to throw `UnsupportedOperationException`.

Liam Miller-Cushon has updated the pull request with a new target base due to a 
merge or a rebase. The incremental webrev excludes the unrelated changes 
brought in by the merge/rebase. The pull request contains five additional 
commits since the last revision:

 - Check m.entrySet().hashCode() in MOAT
 - Merge remote-tracking branch 'origin/master' into 
JDK-8328821-make-clear-consistent
 - Use AbstractImmutableSet
 - Throw UOE for all Map.of().entrySet() mutator methods
 - 8328821: Make the ImmutableCollections clear() call consistent
   
   Without overriding clear(), a call to it in an empty map would
   just return, as iterator.hasNext() would be false. However if
   calling Map.of().clear() throws an exception. To make the
   behavior of Map.of().entrySet().clear() consistent, we need to
   have an implementation of clear() for the entry set that throws
   as well.

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/18522/files
  - new: https://git.openjdk.org/jdk/pull/18522/files/42d67d16..17851d80

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=18522&range=01
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=18522&range=00-01

  Stats: 211051 lines in 4323 files changed: 117813 ins; 68929 del; 24309 mod
  Patch: https://git.openjdk.org/jdk/pull/18522.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18522/head:pull/18522

PR: https://git.openjdk.org/jdk/pull/18522


Re: RFR: 8328821: Map.of().entrySet() mutators should throw UnsupportedOperationException [v2]

2024-05-27 Thread Liam Miller-Cushon
On Mon, 27 May 2024 12:18:23 GMT, Chen Liang  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