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

Reply via email to