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

Inconsistent Javadoc comment and code in intersection(List list1,List list2)in org.apache.commons.collections.ListUtils

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Invalid
    • Affects Version/s: 3.2.1
    • Fix Version/s: None
    • Component/s: Collection
    • Labels:
      None
    • Environment:

      Platform Independent

      Description

      The Javadoc comment below states that the method "throws NullPointerException if either list is null".
      /*......

      • @throws NullPointerException if either list is null
        */
        public static List intersection(final List list1, final List list2)
        ..
        }
        However, when called with a null list1 and an empty list2(i.e., "intersection((List)null, new ArrayList())"), the method executes normally without throwing any exception.

      Suggested Fixes:
      1. Add code "if (list1 == null) throw NullPointerException();" at the beginning of the method body.
      or
      2. Remove "@throws NullPointerException if either list is null" from the Javadoc.
      or
      3. Change "@throws NullPointerException if either list is null" to "@throws NullPointerException if list2 is null or (the list2 is non-empty and the list1 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 - 0.05h
                0.05h
                Remaining:
                Remaining Estimate - 0.05h
                0.05h
                Logged:
                Time Spent - Not Specified
                Not Specified