diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index cca1bd78f..422e25c8d 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -20,6 +20,11 @@
Commons Collections Changes
+
+
+ NullPointerExceptions in CompositeCollection, CompositeSet, and CompositeMap.
+
+
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 f47563d96..8504b36a2 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 extends AbstractIterableMap implements Ser
*/
@SuppressWarnings("unchecked")
public synchronized void addComposited(final Map map) throws IllegalArgumentException {
- for (int i = composite.length - 1; i >= 0; --i) {
- final Collection 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 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[] 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[] 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 8841ab469..4499eb211 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 extends AbstractIterableMapTest {
final CompositeMap map = new CompositeMap<>(buildOne(), buildTwo());
final HashMap 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 extends AbstractIterableMapTest {
final CompositeMap map = new CompositeMap<>(buildOne(), buildTwo());
final HashMap 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 extends AbstractIterableMapTest {
final CompositeMap map = new CompositeMap<>(buildOne(), buildTwo());
final HashMap 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 extends AbstractIterableMapTest {
final CompositeMap map = new CompositeMap<>(buildOne(), buildTwo());
final HashMap three = new HashMap<>();
three.put((K) "5", (V) "five");
+ map.addComposited(null);
map.addComposited(three);
assertTrue(map.containsKey("5"));