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

NullPointerExceptions in CompositeCollection, CompositeSet, and CompositeMap

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 4.2
    • Fix Version/s: 4.4
    • Component/s: Collection, Map, Set
    • Environment:

      Windows 10

      Eclipse IDE for Java Developers     Version: 2018-09 (4.9.0)

      Description

      If we first add a null element into CompositeCollection by CompositeCollection.addComposited(nullElement), projects will crash and throw java.lang.NullPointerException when we call CompositeCollection.size().

      For example, we have following code:

      ArrayList<String> nullList = null;
      CompositeCollection<String> cc = new CompositeCollection<String>(list);
      cc.addComposited(nullList);
      System.out.println(cc.size());

       

      We will get:

      Exception in thread "main" java.lang.NullPointerException
      at org.apache.commons.collections4.collection.CompositeCollection.size(CompositeCollection.java:103)

       

      Because in CompositeCollection.size(), it iterate all items in the Collection, call item.size() and sum up their size. If the item point to null, the program will crash.

       

      This bug also exists in other methods of CompositeCollection. Moreover, CompositeSet and CompositeMap have the same bug.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              sychelsea Yu Shi
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 1h
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified