Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
3.2.1
-
Platform independent
Description
The Javadoc comment below states that the method "throws NullPointerException if the collection is null".
/**
.....
- @param collection the collection to add to, must not be null
- @param object the object to add, if null it will not be added
- @return true if the collection changed
- @throws NullPointerException if the collection is null
*/
public static <T> boolean addIgnoreNull(Collection<T> collection, T object) { return (object != null && collection.add(object)); }However, when called with an null collection and a null object (i.e., "addIgnoreNull((Collection)null, null)"), 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 is null" from the Javadoc.
or
3. Change "@throws NullPointerException if the collection is null" to "@throws NullPointerException if the collection is null and the object is non-null)".