This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-collections.git
The following commit(s) were added to refs/heads/master by this push: new c46666c [COLLECTIONS-710] NullPointerExceptions in CompositeCollection, CompositeSet, and CompositeMap. c46666c is described below commit c46666c5ddbc14bfdb910949de49ac353676f03f Author: Gary Gregory <gardgreg...@gmail.com> AuthorDate: Sat Feb 9 18:00:23 2019 -0500 [COLLECTIONS-710] NullPointerExceptions in CompositeCollection, CompositeSet, and CompositeMap. --- src/changes/changes.xml | 5 +++++ .../commons/collections4/map/CompositeMap.java | 22 ++++++++++++---------- .../commons/collections4/map/CompositeMapTest.java | 4 ++++ 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index cca1bd7..422e25c 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -20,6 +20,11 @@ <title>Commons Collections Changes</title> </properties> <body> + <release version="4.3.1" date="2019-MM-DD" description="Maintenance release."> + <action issue="COLLECTIONS-710" dev="ggregory" type="fix" due-to="Yu Shi, Gary Gregory"> + NullPointerExceptions in CompositeCollection, CompositeSet, and CompositeMap. + </action> + </release> <release version="4.3" date="2018-12-21" description="Update from Java 7 to Java 8, bug fixes, and small changes."> <action issue="COLLECTIONS-691" dev="kinow" type="fix" due-to="Eitan Adler"> Use boolean operator for boolean result. diff --git a/src/main/java/org/apache/commons/collections4/map/CompositeMap.java b/src/main/java/org/apache/commons/collections4/map/CompositeMap.java index f47563d..8504b36 100644 --- a/src/main/java/org/apache/commons/collections4/map/CompositeMap.java +++ b/src/main/java/org/apache/commons/collections4/map/CompositeMap.java @@ -132,19 +132,21 @@ public class CompositeMap<K, V> extends AbstractIterableMap<K, V> implements Ser */ @SuppressWarnings("unchecked") public synchronized void addComposited(final Map<K, V> map) throws IllegalArgumentException { - for (int i = composite.length - 1; i >= 0; --i) { - final Collection<K> intersect = CollectionUtils.intersection(this.composite[i].keySet(), map.keySet()); - if (intersect.size() != 0) { - if (this.mutator == null) { - throw new IllegalArgumentException("Key collision adding Map to CompositeMap"); + if (map != null) { + for (int i = composite.length - 1; i >= 0; --i) { + final Collection<K> intersect = CollectionUtils.intersection(this.composite[i].keySet(), map.keySet()); + if (intersect.size() != 0) { + if (this.mutator == null) { + throw new IllegalArgumentException("Key collision adding Map to CompositeMap"); + } + this.mutator.resolveCollision(this, this.composite[i], map, intersect); } - this.mutator.resolveCollision(this, this.composite[i], map, intersect); } + final Map<K, V>[] temp = new Map[this.composite.length + 1]; + System.arraycopy(this.composite, 0, temp, 0, this.composite.length); + temp[temp.length - 1] = map; + this.composite = temp; } - final Map<K, V>[] temp = new Map[this.composite.length + 1]; - System.arraycopy(this.composite, 0, temp, 0, this.composite.length); - temp[temp.length - 1] = map; - this.composite = temp; } /** diff --git a/src/test/java/org/apache/commons/collections4/map/CompositeMapTest.java b/src/test/java/org/apache/commons/collections4/map/CompositeMapTest.java index 8841ab4..4499eb2 100644 --- a/src/test/java/org/apache/commons/collections4/map/CompositeMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/CompositeMapTest.java @@ -75,6 +75,7 @@ public class CompositeMapTest<K, V> extends AbstractIterableMapTest<K, V> { final CompositeMap<K, V> map = new CompositeMap<>(buildOne(), buildTwo()); final HashMap<K, V> three = new HashMap<>(); three.put((K) "5", (V) "five"); + map.addComposited(null); map.addComposited(three); assertTrue(map.containsKey("5")); try { @@ -90,6 +91,7 @@ public class CompositeMapTest<K, V> extends AbstractIterableMapTest<K, V> { final CompositeMap<K, V> map = new CompositeMap<>(buildOne(), buildTwo()); final HashMap<K, V> three = new HashMap<>(); three.put((K) "5", (V) "five"); + map.addComposited(null); map.addComposited(three); assertTrue(map.containsKey("5")); @@ -106,6 +108,7 @@ public class CompositeMapTest<K, V> extends AbstractIterableMapTest<K, V> { final CompositeMap<K, V> map = new CompositeMap<>(buildOne(), buildTwo()); final HashMap<K, V> three = new HashMap<>(); three.put((K) "5", (V) "five"); + map.addComposited(null); map.addComposited(three); assertTrue(map.containsKey("5")); @@ -119,6 +122,7 @@ public class CompositeMapTest<K, V> extends AbstractIterableMapTest<K, V> { final CompositeMap<K, V> map = new CompositeMap<>(buildOne(), buildTwo()); final HashMap<K, V> three = new HashMap<>(); three.put((K) "5", (V) "five"); + map.addComposited(null); map.addComposited(three); assertTrue(map.containsKey("5"));