[COLLECTIONS-710] NullPointerExceptions in CompositeCollection,

CompositeSet, and CompositeMap.
This commit is contained in:
Gary Gregory 2019-02-09 18:00:23 -05:00
parent 036bbf34d2
commit c46666c5dd
3 changed files with 21 additions and 10 deletions

View File

@ -20,6 +20,11 @@
<title>Commons Collections Changes</title> <title>Commons Collections Changes</title>
</properties> </properties>
<body> <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."> <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"> <action issue="COLLECTIONS-691" dev="kinow" type="fix" due-to="Eitan Adler">
Use boolean operator for boolean result. Use boolean operator for boolean result.

View File

@ -132,6 +132,7 @@ public class CompositeMap<K, V> extends AbstractIterableMap<K, V> implements Ser
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public synchronized void addComposited(final Map<K, V> map) throws IllegalArgumentException { public synchronized void addComposited(final Map<K, V> map) throws IllegalArgumentException {
if (map != null) {
for (int i = composite.length - 1; i >= 0; --i) { for (int i = composite.length - 1; i >= 0; --i) {
final Collection<K> intersect = CollectionUtils.intersection(this.composite[i].keySet(), map.keySet()); final Collection<K> intersect = CollectionUtils.intersection(this.composite[i].keySet(), map.keySet());
if (intersect.size() != 0) { if (intersect.size() != 0) {
@ -146,6 +147,7 @@ public class CompositeMap<K, V> extends AbstractIterableMap<K, V> implements Ser
temp[temp.length - 1] = map; temp[temp.length - 1] = map;
this.composite = temp; this.composite = temp;
} }
}
/** /**
* Remove a Map from the composite. * Remove a Map from the composite.

View File

@ -75,6 +75,7 @@ public class CompositeMapTest<K, V> extends AbstractIterableMapTest<K, V> {
final CompositeMap<K, V> map = new CompositeMap<>(buildOne(), buildTwo()); final CompositeMap<K, V> map = new CompositeMap<>(buildOne(), buildTwo());
final HashMap<K, V> three = new HashMap<>(); final HashMap<K, V> three = new HashMap<>();
three.put((K) "5", (V) "five"); three.put((K) "5", (V) "five");
map.addComposited(null);
map.addComposited(three); map.addComposited(three);
assertTrue(map.containsKey("5")); assertTrue(map.containsKey("5"));
try { try {
@ -90,6 +91,7 @@ public class CompositeMapTest<K, V> extends AbstractIterableMapTest<K, V> {
final CompositeMap<K, V> map = new CompositeMap<>(buildOne(), buildTwo()); final CompositeMap<K, V> map = new CompositeMap<>(buildOne(), buildTwo());
final HashMap<K, V> three = new HashMap<>(); final HashMap<K, V> three = new HashMap<>();
three.put((K) "5", (V) "five"); three.put((K) "5", (V) "five");
map.addComposited(null);
map.addComposited(three); map.addComposited(three);
assertTrue(map.containsKey("5")); 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 CompositeMap<K, V> map = new CompositeMap<>(buildOne(), buildTwo());
final HashMap<K, V> three = new HashMap<>(); final HashMap<K, V> three = new HashMap<>();
three.put((K) "5", (V) "five"); three.put((K) "5", (V) "five");
map.addComposited(null);
map.addComposited(three); map.addComposited(three);
assertTrue(map.containsKey("5")); 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 CompositeMap<K, V> map = new CompositeMap<>(buildOne(), buildTwo());
final HashMap<K, V> three = new HashMap<>(); final HashMap<K, V> three = new HashMap<>();
three.put((K) "5", (V) "five"); three.put((K) "5", (V) "five");
map.addComposited(null);
map.addComposited(three); map.addComposited(three);
assertTrue(map.containsKey("5")); assertTrue(map.containsKey("5"));