RFR: 8221924: get(null) on single-entry unmodifiable Map returns null instead of throwing NPE

Peter Levart peter.levart at gmail.com
Fri Apr 5 07:04:59 UTC 2019


Map1.get() should be much faster with this patch too, right?

Peter

On 4/4/19 11:11 PM, Stuart Marks wrote:
> Hi all,
>
> An unmodifiable map with one entry doesn't throw NPE from get(null). 
> Instead, it returns null. This makes it quite an outlier:
>
> Map.of().get(null) ==> NPE
> Map.of().containsKey(null) ==> NPE
> Map.of().containsValue(null) ==> NPE
>
> Map.of(1, 2).get(null) ==> returns null  ***
> Map.of(1, 2).containsKey(null) ==> NPE
> Map.of(1, 2).containsValue(null) ==> NPE
>
> Map.of(1, 2, 3, 4).get(null) ==> NPE
> Map.of(1, 2, 3, 4).containsKey(null) ==> NPE
> Map.of(1, 2, 3, 4).containsValue(null) ==> NPE
>
> It should be fixed to throw NPE like all the other cases.
>
> This is a tiny incompatible change, so I intend to file a CSR. Tier1, 
> 2, and 3 tests all pass though.
>
> I think this change should also be backported to 11. We're fairly 
> early in the 11 LTS lifetime, so it'd be good to fix this now.
>
> Bug:
>
>     https://bugs.openjdk.java.net/browse/JDK-8221924
>
> Webrev:
>
>     http://cr.openjdk.java.net/~smarks/reviews/8221924/webrev.0/
>
> Thanks,
>
> s'marks



More information about the core-libs-dev mailing list