From 7df57879c92a467cd71860e6cfe14a04a49fd031 Mon Sep 17 00:00:00 2001 From: Sebastian Bazley Date: Mon, 24 Jun 2013 19:48:29 +0000 Subject: [PATCH] COLLECTIONS-474 Exception in ListOrderedMap#putAll if map contains null values git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1496182 13f79535-47bb-0310-9956-ffa450edef68 --- src/changes/changes.xml | 6 ++++++ .../commons/collections4/map/ListOrderedMap.java | 10 +++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 0955e510a..365e259db 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -21,6 +21,12 @@ + + + Exception in ListOrderedMap#putAll if map contains null values. + + + Made field "collection" in class "AbstractCollectionDecorator" private and added diff --git a/src/main/java/org/apache/commons/collections4/map/ListOrderedMap.java b/src/main/java/org/apache/commons/collections4/map/ListOrderedMap.java index 289711424..9f1ee932c 100644 --- a/src/main/java/org/apache/commons/collections4/map/ListOrderedMap.java +++ b/src/main/java/org/apache/commons/collections4/map/ListOrderedMap.java @@ -239,12 +239,16 @@ public class ListOrderedMap * 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 map) { for (final Map.Entry 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 {