You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Yu Shi (JIRA)" <ji...@apache.org> on 2019/01/29 22:01:00 UTC

[jira] [Created] (COLLECTIONS-710) Calling CompositeCollection.size() will cash if the list contains null element.

Yu Shi created COLLECTIONS-710:
----------------------------------

             Summary: Calling CompositeCollection.size() will cash if  the list contains null element.
                 Key: COLLECTIONS-710
                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-710
             Project: Commons Collections
          Issue Type: Bug
          Components: Collection, Map, Set
    Affects Versions: 4.2
         Environment: Windows 10

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


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.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)