RFR: 8351230: Collections.synchronizedList returns a list that is not thread-safe [v2]

Stuart Marks smarks at openjdk.org
Mon May 5 23:36:36 UTC 2025


On Sun, 4 May 2025 17:51:48 GMT, Luca Kellermann <duke at openjdk.org> wrote:

>> Stuart Marks has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Reversed view of SynchronizedRandomAccessList should also be RandomAccess.
>>   Add tests to ensure RandomAccess is preserved when reversing.
>
> src/java.base/share/classes/java/util/Collections.java line 2837:
> 
>> 2835:                 return reversedView;
>> 2836:             }
>> 2837:         }
> 
> `SynchronizedRandomAccessList` overrides `subList`, should it also override `reversed`?

Good point, yes it should! At least, it should ensure that the reversed view of a random access synchronized list should also be random access -- which the current code doesn't do. Overriding reversed() in the RA subclass is probably the clearest way to do that. I'll also take the opportunity to expand test coverage, as I don't think the reversed-view-of-RA-is-also-RA is covered anywhere.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/24990#discussion_r2074366852


More information about the core-libs-dev mailing list