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

CollectionUtils.retainAll() not throwing proper NullPointerException(NPE)

    XMLWordPrintableJSON

Details

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

    Description

      The CollectionUtils.retainAll(Iterable<E> collection, Iterable<? extends E> retain, Equator<? super E> equator) does not throw a NullPointerException(NPE) when one of the parameters is null.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 {
              HashSet<Integer> hashSet = new HashSet<Integer>(1095, 1095);
              try {
                   Collection<Integer> collection =
                   CollectionUtils.retainAll((Iterable<Integer>) hashSet,
                   (Iterable<? extends Integer>) hashSet,
                   (Equator<? super Integer>) null);
                   org.junit.Assert.fail();        
              }
              catch (java.lang.NullPointerException e) {
              //NPE caught and test successful
              }
          }
      }

      The last Equator parameter is null and a NPE should be thrown, however the method executes normally, and test case fails.

      Attachments

        Activity

          People

            Unassigned Unassigned
            eTroc Elia Bertolina
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: