RFR: 8272042: java.util.ImmutableCollections$Map1 and MapN should not be @ValueBased [v2]

Stuart Marks smarks at openjdk.java.net
Tue Nov 23 04:09:10 UTC 2021


On Fri, 19 Nov 2021 20:47:40 GMT, Roger Riggs <rriggs at openjdk.org> wrote:

>> The `jdk.internal.ValueBased` annotation was incorrectly applied to subclasses of java.util.AbstractMap.
>> [ValueBased](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/doc-files/ValueBased.html) requires that supertypes have no instance fields; AbstractMap has instance fields keySet and values.
>> 
>> Remove the internal @ValueBased annotation for subclasses of AbstractMap including:
>> AbstractImmutableMap, Map1, and MapN.
>
> Roger Riggs has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Added comment explaining why immutable Maps are not 'ValueBased'

Marked as reviewed by smarks (Reviewer).

Yes, we want to leave the "value-based" stipulation in the specification, even if the ValueBased annotation is removed. In the future we might be able to remove the dependency on `AbstractMap` and thus avoid the mutable fields in the unmodifiable collections. Or maybe `AbstractMap` should lose them entirely. The `keySet` and `values` collections are fairly small objects themselves, so caching them might not be much benefit in the first place.

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

PR: https://git.openjdk.java.net/jdk/pull/6480


More information about the core-libs-dev mailing list