Details
-
Type:
Bug
-
Status: Closed
-
Priority:
Major
-
Resolution: Not A Problem
-
Affects Version/s: 2.1, 2.1.1, 3.0, 3.1, 3.2
-
Fix Version/s: None
-
Component/s: Collection
-
Labels:
-
Environment:
Platform Independent
Description
The Javadoc comment below states that the method "throws NullPointerException if the collection or array is null".
/**
- Adds all elements in the array to the given collection.
- @param collection the collection to add to, must not be null
- @param elements the array of elements to add, must not be null
- @throws NullPointerException if the collection or array is null
*/
public static void addAll(Collection collection, Object[] elements)Unknown macro: { for (int i = 0, size = elements.length; i < size; i++) { collection.add(elements[i]); } }
However, when called with an empty array and a null collection (i.e., "addAll((Collection)null, new Object[])"), the method executes normally without throwing any exception.
Suggested Fixes:
1. Add code "if (collection == null) throw NullPointerException();" at the beginning of the method body.
or
2. Remove "@throws NullPointerException if the collection or array is null" from the Javadoc.
or
3. Change "@throws NullPointerException if the collection or array is null" to "@throws NullPointerException if the array is null or (the array is non-empty and the collection is null)".