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.

Also, thanks for your comments @jaikiran !

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

PR Comment: https://git.openjdk.org/jdk/pull/31177#issuecomment-4994177653

Reply via email to