You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2022/09/24 20:36:00 UTC
[jira] [Work logged] (COLLECTIONS-814) CollectionUtils.removeAll() not throwing proper NullPointerException(NPE) if the first parameter is empty
[ https://issues.apache.org/jira/browse/COLLECTIONS-814?focusedWorklogId=811870&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-811870 ]
ASF GitHub Bot logged work on COLLECTIONS-814:
----------------------------------------------
Author: ASF GitHub Bot
Created on: 24/Sep/22 20:35
Start Date: 24/Sep/22 20:35
Worklog Time Spent: 10m
Work Description: angusdev opened a new pull request, #340:
URL: https://github.com/apache/commons-collections/pull/340
[COLLECTIONS-814](https://issues.apache.org/jira/browse/COLLECTIONS-814)
CollectionUtils.removeAll() not throwing proper NullPointerException(NPE) if the first parameter is empty
Add null check in ListUtil.removeAll()
Issue Time Tracking
-------------------
Worklog Id: (was: 811870)
Remaining Estimate: 0h
Time Spent: 10m
> CollectionUtils.removeAll() not throwing proper NullPointerException(NPE) if the first parameter is empty
> ---------------------------------------------------------------------------------------------------------
>
> Key: COLLECTIONS-814
> URL: https://issues.apache.org/jira/browse/COLLECTIONS-814
> Project: Commons Collections
> Issue Type: Bug
> Affects Versions: 4.4
> Reporter: Elia Bertolina
> Priority: Major
> Time Spent: 10m
> Remaining Estimate: 0h
>
> The CollectionUtils.removeAll(Collection<E> collection, Collection<?> remove) does not throw a NullPointerException(NPE) when the “remove” parameters is null, but only if the “collection” parameter is empty.
> In the documentation it is stated that an NPE will be thrown if any of the parameters is null.
> However, in this test case:
>
> {code:java}
> public class CollectionUtils_failure_Test {
> public void test() throws Throwable {
> LinkedList<InstanceofPredicate> linkedList = new
> LinkedList<InstanceofPredicate>();
> try {
> Collection<InstanceofPredicate> collection =
> CollectionUtils.removeAll(
> (Collection<InstanceofPredicate>)linkedList,
> (Collection<?>) null);
> org.junit.Assert.fail();
> } catch (java.lang.NullPointerException e) {
> //Exception caught and test successful
> }
> }
> } {code}
>
> This is a special case (first parameter needs to be empty and the second needs to be null) but this behavior is missing in the documentation. While this behavior is somehow correct (removing a null Object from an empty Collection we should obtain an empty Collection) I think throwing an NPE would be more in line with the documentation provided.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)