On Fri, 15 May 2026 19:38:08 GMT, Stuart Marks <[email protected]> wrote:
>> 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).
>
> Stuart Marks has updated the pull request incrementally with one additional
> commit since the last revision:
>
> Clean up "unmodifiable" data provider.
The changes look reasonable to me. I had a question about why this change is
limited to certain methods of `Collections`. I have added that to the JBS issue
as an comment.
-------------
Marked as reviewed by jpai (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/31177#pullrequestreview-4334368672