Commons Collections
  1. Commons Collections
  2. COLLECTIONS-400

Inconsistent Javadoc comment and code in addIgnoreNull(Collection<T>, T) in org.apache.commons.collections.CollectionUtils

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.2.1
    • Fix Version/s: 4.0-alpha1, 4.0
    • Component/s: Collection
    • Labels:
    • Environment:

      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)".

        Activity

        Hide
        Thomas Neidhart added a comment -

        Thanks for the report. I have added the missing null check in r1311344.

        Show
        Thomas Neidhart added a comment - Thanks for the report. I have added the missing null check in r1311344.
        Hide
        Hudson added a comment -

        Integrated in commons-collections #16 (See https://builds.apache.org/job/commons-collections/16/)
        COLLECTIONS-400 Added missing null check, thanks to Shin Hwei Tan. (Revision 1311344)

        Result = SUCCESS
        tn : http://svn.apache.org/viewvc/?view=rev&rev=1311344
        Files :

        • /commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/CollectionUtils.java
        Show
        Hudson added a comment - Integrated in commons-collections #16 (See https://builds.apache.org/job/commons-collections/16/ ) COLLECTIONS-400 Added missing null check, thanks to Shin Hwei Tan. (Revision 1311344) Result = SUCCESS tn : http://svn.apache.org/viewvc/?view=rev&rev=1311344 Files : /commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/CollectionUtils.java

          People

          • Assignee:
            Unassigned
            Reporter:
            SHIN HWEI TAN
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 0.05h
              0.05h
              Remaining:
              Remaining Estimate - 0.05h
              0.05h
              Logged:
              Time Spent - Not Specified
              Not Specified

                Development