Uploaded image for project: 'Commons Collections'
  1. Commons Collections
  2. COLLECTIONS-385

Inconsistent Javadoc comment and code in addAll(Collection, Object[]) in org.apache.commons.collections.CollectionUtils

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

        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 - 5m
                5m
                Remaining:
                Remaining Estimate - 5m
                5m
                Logged:
                Time Spent - Not Specified
                Not Specified