Uploaded image for project: '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
    • Status: Closed
    • Priority: 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)".

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              shinhwei 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