From 9a150225203ffc217dfcbaa496d6c3466d6f7249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Prante?= Date: Wed, 14 Oct 2020 14:38:57 +0200 Subject: [PATCH] fix NPE in putAll --- .../xbib/datastructures/tiny/IndexedCollectionBase.java | 3 +++ .../java/org/xbib/datastructures/tiny/IndexedMapBase.java | 3 +++ .../java/org/xbib/datastructures/tiny/TinyMapTest.java | 8 ++++++++ gradle.properties | 2 +- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/datastructures-tiny/src/main/java/org/xbib/datastructures/tiny/IndexedCollectionBase.java b/datastructures-tiny/src/main/java/org/xbib/datastructures/tiny/IndexedCollectionBase.java index d334406..f0dc371 100644 --- a/datastructures-tiny/src/main/java/org/xbib/datastructures/tiny/IndexedCollectionBase.java +++ b/datastructures-tiny/src/main/java/org/xbib/datastructures/tiny/IndexedCollectionBase.java @@ -45,6 +45,9 @@ public abstract class IndexedCollectionBase extends AbstractCollection imp @Override public void forEach(Consumer action) { + if (action == null) { + return; + } for (int i = 0; i < rawSize(); i++) { if (!isRemoved(i)) { action.accept(getEntryAt(i)); diff --git a/datastructures-tiny/src/main/java/org/xbib/datastructures/tiny/IndexedMapBase.java b/datastructures-tiny/src/main/java/org/xbib/datastructures/tiny/IndexedMapBase.java index d85aea3..f041870 100644 --- a/datastructures-tiny/src/main/java/org/xbib/datastructures/tiny/IndexedMapBase.java +++ b/datastructures-tiny/src/main/java/org/xbib/datastructures/tiny/IndexedMapBase.java @@ -112,6 +112,9 @@ public abstract class IndexedMapBase implements IndexedMap { @Override public void putAll(Map m) { + if (m == null) { + return; + } m.forEach(this::put); } diff --git a/datastructures-tiny/src/test/java/org/xbib/datastructures/tiny/TinyMapTest.java b/datastructures-tiny/src/test/java/org/xbib/datastructures/tiny/TinyMapTest.java index dcaa9d6..6fb189d 100644 --- a/datastructures-tiny/src/test/java/org/xbib/datastructures/tiny/TinyMapTest.java +++ b/datastructures-tiny/src/test/java/org/xbib/datastructures/tiny/TinyMapTest.java @@ -220,6 +220,14 @@ public class TinyMapTest { assertEquals(100, set.size()); } + @Test + public void testPutAllNull() { + TinyMap.Builder builder = TinyMap.builder(); + builder.put("a", "b"); + builder.putAll(null); + assertEquals(1, builder.build().size()); + } + private void testCount(int count, boolean withNull) { TinyMap.Builder builder = TinyMap.builder(); LinkedHashMap expectedMap = new LinkedHashMap<>(); diff --git a/gradle.properties b/gradle.properties index 3786e99..f24d173 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ group = org.xbib name = datastructures -version = 0.0.2 +version = 0.0.3 gradle.wrapper.version = 6.6.1