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

CollectionUtils.removeAll() not throwing proper NullPointerException(NPE) if the first parameter is empty

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 4.4
    • 4.5.0-M1
    • None
    • None

    Description

      The CollectionUtils.removeAll(Collection<E> collection, Collection<?> remove) does not throw a NullPointerException(NPE) when the “remove” parameters is null, but only if the “collection” parameter is empty.

      In the documentation it is stated that an NPE will be thrown if any of the parameters is null.

      However, in this test case:

       

      public class CollectionUtils_failure_Test {
          public void test() throws Throwable {
              LinkedList<InstanceofPredicate> linkedList = new
              LinkedList<InstanceofPredicate>();
              try {
                  Collection<InstanceofPredicate> collection =
                  CollectionUtils.removeAll(
                  (Collection<InstanceofPredicate>)linkedList,
                  (Collection<?>) null);
                  org.junit.Assert.fail();
              } catch (java.lang.NullPointerException e) {
                 //Exception caught and test successful
              }    
          }
      } 

       

      This is a special case (first parameter needs to be empty and the second needs to be null) but this behavior is missing in the documentation. While this behavior is somehow correct (removing a null Object from an empty Collection we should obtain an empty Collection) I think throwing an NPE would be more in line with the documentation provided.

      Attachments

        Activity

          People

            kinow Bruno P. Kinoshita
            eTroc Elia Bertolina
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 50m
                50m