[
https://issues.apache.org/jira/browse/COLLECTIONS-710?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Yu Shi updated COLLECTIONS-710:
-------------------------------
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.
was:
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.
> 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
> Priority: Minor
> Labels: nullpointerexception
> 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
(v7.6.3#76005)