[COLLECTIONS-521] Fix MultiKeyMap when using two key arguments and the second is null. Thanks to Maxime Nay.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1592893 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Thomas Neidhart 2014-05-06 21:38:05 +00:00
parent a85fe84ce6
commit 320c0acf89
3 changed files with 21 additions and 1 deletions

View File

@ -22,6 +22,10 @@
<body>
<release version="4.1" date="TBD" description="">
<action issue="COLLECTIONS-521" dev="tn" type="fix" due-to="Maxime Nay">
"MultiKeyMap" was throwing a "NullPointerException" for various operations
if two key arguments have been used and the second was "null".
</action>
<action issue="COLLECTIONS-522" dev="tn" type="fix" due-to="Erik">
Updated code example for "PredicatedList".
</action>

View File

@ -249,7 +249,7 @@ public class MultiKeyMap<K, V> extends AbstractMapDecorator<MultiKey<? extends K
return
multi.size() == 2 &&
(key1 == multi.getKey(0) || key1 != null && key1.equals(multi.getKey(0))) &&
(key2 == multi.getKey(1) || key1 != null && key2.equals(multi.getKey(1)));
(key2 == multi.getKey(1) || key2 != null && key2.equals(multi.getKey(1)));
}
//-----------------------------------------------------------------------

View File

@ -300,6 +300,22 @@ public class MultiKeyMapTest<K, V> extends AbstractIterableMapTest<MultiKey<? ex
}
}
public void testMultiKeyPutWithNullKey() {
final MultiKeyMap<String, String> map = new MultiKeyMap<String, String>();
map.put("a", null, "value1");
map.put("b", null, "value2");
map.put("c", null, "value3");
map.put("a", "z", "value4");
map.put("a", null, "value5");
map.put(null, "a", "value6");
map.put(null, null, "value7");
assertEquals(6, map.size());
assertEquals("value5", map.get("a", null));
assertEquals("value4", map.get("a", "z"));
assertEquals("value6", map.get(null, "a"));
}
public void testMultiKeyRemove() {
final MultiKey<K>[] keys = getMultiKeyKeys();
final V[] values = getSampleValues();