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

Stuart Marks stuart.marks at oracle.com
Fri Apr 5 22:04:59 UTC 2019


Hi all,

Can I get a review of the CSR for this change?

     https://bugs.openjdk.java.net/browse/JDK-8222002

The CSR is mostly a restatement of the issue, somewhat more complete, along with 
an assessment of the compatibility risk (low but nonzero).

Thanks,

s'marks

On 4/4/19 2: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