RFR: 6323374: (coll) Optimize Collections.unmodifiable* and synchronized* [v3]

liach github.com+7806504+liach at openjdk.java.net
Fri Feb 19 01:55:40 UTC 2021


On Thu, 18 Feb 2021 16:18:42 GMT, jmehrens <github.com+28367473+jmehrens at openjdk.org> wrote:

>> Yes -- I think in response to this it makes more sense to pull the `ImmutableCollections` classes out for now and only focus on the wrapping of the classes within `Collections` so we aren't blocked by studying and rectifying these inconsistencies.
>
> Maybe it is not correct for UnmodifiableEntrySet::contains to short circuit?  What if the implementation was changed to:
> 
> `public boolean contains(Object o) {
>             if (!(o instanceof Map.Entry))
>                 return c.contains(o); //false, NPE, or CCE
>             return c.contains(
>                 new UnmodifiableEntry<>((Map.Entry<?,?>) o));
> }`

This however changes the behavior of unmodifiable maps compared to before; i.e. before for other entry sets, they could not throw exception if the object passed was not map entry; now they can.

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

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


More information about the core-libs-dev mailing list