RFR: 8266571: Sequenced Collections [v3]

Stuart Marks smarks at openjdk.org
Tue Mar 28 01:14:01 UTC 2023


On Fri, 24 Mar 2023 21:28:18 GMT, Tagir F. Valeev <tvaleev at openjdk.org> wrote:

>> Stuart Marks has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 78 commits:
>> 
>>  - Merge branch 'master' into JDK-8266571-SequencedCollections
>>  - Update copyrights.
>>  - More specification tweaks.
>>  - Add simple overrides to ArrayList.
>>  - Specification cleanups.
>>  - Update spec of CopyOnWriteArrayList::reversed.
>>  - Move AbstractViewCollection to AbstractMap.ViewCollection to avoid exposing it publicly.
>>  - Merge branch 'master' into JDK-8266571-SequencedCollections
>>    Resolve conflict by deleting IdentityLinkedList.java
>>  - Merge branch 'master' into JDK-8266571-SequencedCollections
>>  - Fix indentation.
>>  - ... and 68 more: https://git.openjdk.org/jdk/compare/6aec6f3a...91c4eabe
>
> src/java.base/share/classes/java/util/LinkedHashMap.java line 782:
> 
>> 780:             return svs;
>> 781:         } else {
>> 782:             return new LinkedValues(false);
> 
> Is it possible that this branch is visited? If yes, probably it worth adding a comment when this happens.

Good point! This was a vestige of an earlier incarnation where a values() view from a subclass could be stored in the `values` field, and of course it would not be a SequencedCollection; thus a new one would have to be created in order to satisfy this method's requirements. However, because the `values` field is a cache that is only set here, we can rely on it to be sequenced. So I've simplified this to assume that the downcast will be successful.

This highlights the fact that a subclass that overrides values() to create and return its own view collection will potentially have different semantics from the view returned by sequencedValues(). For example, they might return different mappings. Unfortunately I think this is unavoidable.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/7387#discussion_r1149926145



More information about the client-libs-dev mailing list