mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8221924: get(null) on single-entry unmodifiable Map returns null instead of throwing NPE
Reviewed-by: redestad, lancea
This commit is contained in:
parent
b0c2b42e40
commit
1aa784cdac
2 changed files with 12 additions and 2 deletions
|
@ -881,6 +881,11 @@ class ImmutableCollections {
|
|||
return Set.of(new KeyValueHolder<>(k0, v0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(Object o) {
|
||||
return o.equals(k0) ? v0 : null; // implicit nullcheck of o
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey(Object o) {
|
||||
return o.equals(k0); // implicit nullcheck of o
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -50,7 +50,7 @@ import static org.testng.Assert.fail;
|
|||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8048330
|
||||
* @bug 8048330 8221924
|
||||
* @summary Test convenience static factory methods on Map.
|
||||
* @run testng MapFactories
|
||||
*/
|
||||
|
@ -386,6 +386,11 @@ public class MapFactories {
|
|||
act.containsKey(null);
|
||||
}
|
||||
|
||||
@Test(dataProvider="all", expectedExceptions=NullPointerException.class)
|
||||
public void getNullShouldThrowNPE(Map<Integer,String> act, Map<Integer,String> exp) {
|
||||
act.get(null);
|
||||
}
|
||||
|
||||
@Test(dataProvider="all")
|
||||
public void serialEquality(Map<Integer, String> act, Map<Integer, String> exp) {
|
||||
// assume that act.equals(exp) tested elsewhere
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue