Author: sebb
Date: Mon Jun 24 19:48:29 2013
New Revision: 1496182

URL: http://svn.apache.org/r1496182
Log:
COLLECTIONS-474 Exception in ListOrderedMap#putAll if map contains null values

Modified:
    commons/proper/collections/trunk/src/changes/changes.xml
    
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/map/ListOrderedMap.java

Modified: commons/proper/collections/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/changes/changes.xml?rev=1496182&r1=1496181&r2=1496182&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/changes/changes.xml (original)
+++ commons/proper/collections/trunk/src/changes/changes.xml Mon Jun 24 
19:48:29 2013
@@ -21,6 +21,12 @@
   </properties>
   <body>
 
+  <release version="4.x" date="TBA" description="TBA">
+    <action issue="COLLECTIONS-474" dev="sebb" type="fix" due-to="Ning Chen ">
+     Exception in ListOrderedMap#putAll if map contains null values.
+    </action>
+  </release>
+
   <release version="4.0" date="TBA" description="Next release">
     <action issue="COLLECTIONS-473" dev="tn" type="update" due-to="sebb">
       Made field "collection" in class "AbstractCollectionDecorator" private 
and added

Modified: 
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/map/ListOrderedMap.java
URL: 
http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/map/ListOrderedMap.java?rev=1496182&r1=1496181&r2=1496182&view=diff
==============================================================================
--- 
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/map/ListOrderedMap.java
 (original)
+++ 
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/map/ListOrderedMap.java
 Mon Jun 24 19:48:29 2013
@@ -239,12 +239,16 @@ public class ListOrderedMap<K, V>
      * the specified index.
      *
      * @param index the index in the Map to start at.
-     * @param map the Map containing the values to be added.
+     * @param map the Map containing the entries to be added.
      */
     public void putAll(int index, final Map<? extends K, ? extends V> map) {
         for (final Map.Entry<? extends K, ? extends V> entry : map.entrySet()) 
{
-            final V old = put(index, entry.getKey(), entry.getValue());
-            if (old == null) {
+            final K key = entry.getKey();
+            final boolean contains = containsKey(key);
+            // The return value of put is null if the key did not exist OR the 
value was null
+            // so it cannot be used to determine whether the key was added
+            put(index, entry.getKey(), entry.getValue());
+            if (!contains) {
                 // if no key was replaced, increment the index
                 index++;
             } else {


Reply via email to