mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8308167: SequencedMap::firstEntry throws NPE when first entry has null key or value
Reviewed-by: bchristi
This commit is contained in:
parent
4b1534989b
commit
6d155a47f1
4 changed files with 214 additions and 6 deletions
|
@ -25,6 +25,8 @@
|
|||
|
||||
package java.util;
|
||||
|
||||
import jdk.internal.util.NullableKeyValueHolder;
|
||||
|
||||
/**
|
||||
* A Map that has a well-defined encounter order, that supports operations at both ends, and
|
||||
* that is reversible. The <a href="SequencedCollection.html#encounter">encounter order</a>
|
||||
|
@ -148,7 +150,7 @@ public interface SequencedMap<K, V> extends Map<K, V> {
|
|||
*/
|
||||
default Map.Entry<K,V> firstEntry() {
|
||||
var it = entrySet().iterator();
|
||||
return it.hasNext() ? Map.Entry.copyOf(it.next()) : null;
|
||||
return it.hasNext() ? new NullableKeyValueHolder<>(it.next()) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -165,7 +167,7 @@ public interface SequencedMap<K, V> extends Map<K, V> {
|
|||
*/
|
||||
default Map.Entry<K,V> lastEntry() {
|
||||
var it = reversed().entrySet().iterator();
|
||||
return it.hasNext() ? Map.Entry.copyOf(it.next()) : null;
|
||||
return it.hasNext() ? new NullableKeyValueHolder<>(it.next()) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -185,7 +187,7 @@ public interface SequencedMap<K, V> extends Map<K, V> {
|
|||
default Map.Entry<K,V> pollFirstEntry() {
|
||||
var it = entrySet().iterator();
|
||||
if (it.hasNext()) {
|
||||
var entry = Map.Entry.copyOf(it.next());
|
||||
var entry = new NullableKeyValueHolder<>(it.next());
|
||||
it.remove();
|
||||
return entry;
|
||||
} else {
|
||||
|
@ -210,7 +212,7 @@ public interface SequencedMap<K, V> extends Map<K, V> {
|
|||
default Map.Entry<K,V> pollLastEntry() {
|
||||
var it = reversed().entrySet().iterator();
|
||||
if (it.hasNext()) {
|
||||
var entry = Map.Entry.copyOf(it.next());
|
||||
var entry = new NullableKeyValueHolder<>(it.next());
|
||||
it.remove();
|
||||
return entry;
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue