diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 6a664df94..5cfe7ac80 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -192,6 +192,9 @@ Changed classes / methods Fixed Bugs ---------- + o [COLLECTIONS-474] ListOrderedMap#putAll(index, Object, Object) does not throw an exception anymore if the + map contains null values. Additionally added javadoc clarification on the supported bounds + for the index parameter. Thanks to Ning Chen. o [COLLECTIONS-472] Improved performance of "AbstractMapBag#containsAll(Collection)" by returning immediately after a difference has been found. Thanks to Adrian Nistor. o [COLLECTIONS-461] Added additional clarification to javadoc of interface "Put" wrt return type of diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 365e259db..783de89ce 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -21,13 +21,10 @@ - + Exception in ListOrderedMap#putAll if map contains null values. - - - Made field "collection" in class "AbstractCollectionDecorator" private and added setter "setCollection(Collection)" with scope protected to set the decorated collection 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 9f1ee932c..c01b84742 100644 --- a/src/main/java/org/apache/commons/collections4/map/ListOrderedMap.java +++ b/src/main/java/org/apache/commons/collections4/map/ListOrderedMap.java @@ -240,8 +240,12 @@ public class ListOrderedMap * * @param index the index in the Map to start at. * @param map the Map containing the entries to be added. + * @throws IndexOutOfBoundsException if the index is out of range [0, size] */ public void putAll(int index, final Map map) { + if (index < 0 || index > insertOrder.size()) { + throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + insertOrder.size()); + } for (final Map.Entry entry : map.entrySet()) { final K key = entry.getKey(); final boolean contains = containsKey(key); @@ -437,10 +441,14 @@ public class ListOrderedMap * @param key the key * @param value the value * @return the value previously mapped to the key - * @throws IndexOutOfBoundsException if the index is out of range + * @throws IndexOutOfBoundsException if the index is out of range [0, size] * @since 3.2 */ public V put(int index, final K key, final V value) { + if (index < 0 || index > insertOrder.size()) { + throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + insertOrder.size()); + } + final Map m = decorated(); if (m.containsKey(key)) { final V result = m.remove(key);