[jira] [Resolved] (COLLECTIONS-710) NullPointerExceptions in CompositeCollection, CompositeSet, and CompositeMap

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[jira] [Resolved] (COLLECTIONS-710) NullPointerExceptions in CompositeCollection, CompositeSet, and CompositeMap

JIRA jira@apache.org

     [ https://issues.apache.org/jira/browse/COLLECTIONS-710?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gary Gregory resolved COLLECTIONS-710.
       Resolution: Fixed
    Fix Version/s: 4.3.1


Thank you for your report.

Fixes are in git master. Please verify and close. If there are still problems, please provide a PR on GitHub.


> NullPointerExceptions in CompositeCollection, CompositeSet, and CompositeMap
> ----------------------------------------------------------------------------
>                 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
>            Priority: Major
>              Labels: nullpointerexception
>             Fix For: 4.3.1
>   Original Estimate: 1h
>  Remaining Estimate: 1h
> 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