Change the following collections to be strictly unmodifiable:

 - The reversed view of Collections.unmodifiableList()
 - The reversed view Collections.unmodifiableSortedSet()

"Strictly unmodifiable" means that, if a mutator method is called that doesn't 
actually attempt to modify the collection, then UnsupportedOperationException 
will be thrown instead of the method returning normally. For example, consider 
the following:

    Collections.unmodifiableList(new ArrayList<>()).reversed().remove("x") 
    Collections.unmodifiableSortedSet(new TreeSet<>()).reversed().removeIf(x -> 
false) 

Both of these currently return false. With this change, both will throw 
UnsupportedOperationException.

This improves consistency of behavior of reversed views, which were all 
intended to be strictly unmodifiable if the backing collection is unmodifiable. 
This also improves consistency of the tests, which had some cases commented out 
because of these edge cases.

See bug [JDK-8383625](https://bugs.openjdk.org/browse/JDK-8383625) for full 
discussion.

---------
- [x] I confirm that I make this contribution in accordance with the [OpenJDK 
Interim AI Policy](https://openjdk.org/legal/ai).

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

Commit messages:
 - Separate strict/non-strict providers and assertions.
 - Merge branch 'master' into JDK-8383625-unmodifiable-reversed
 - initial attempt at fix

Changes: https://git.openjdk.org/jdk/pull/31177/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=31177&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8383625
  Stats: 92 lines in 3 files changed: 64 ins; 14 del; 14 mod
  Patch: https://git.openjdk.org/jdk/pull/31177.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/31177/head:pull/31177

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

Reply via email to