You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ki...@apache.org on 2022/10/19 02:12:52 UTC
[commons-collections] 01/03: [COLLECTIONS-814] CollectionUtils.removeAll() not throwing proper NullPointerException(NPE) if the first parameter is empty
This is an automated email from the ASF dual-hosted git repository.
kinow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-collections.git
commit 17bed2b5551c6489264d47e1009f45c27236f71c
Author: Angus <an...@gmail.com>
AuthorDate: Sat Sep 24 21:32:53 2022 +0100
[COLLECTIONS-814] CollectionUtils.removeAll() not throwing proper NullPointerException(NPE) if the first parameter is empty
Add null check
---
src/main/java/org/apache/commons/collections4/ListUtils.java | 2 ++
src/test/java/org/apache/commons/collections4/ListUtilsTest.java | 6 ++++++
2 files changed, 8 insertions(+)
diff --git a/src/main/java/org/apache/commons/collections4/ListUtils.java b/src/main/java/org/apache/commons/collections4/ListUtils.java
index e62a72f08..274e2b50a 100644
--- a/src/main/java/org/apache/commons/collections4/ListUtils.java
+++ b/src/main/java/org/apache/commons/collections4/ListUtils.java
@@ -533,6 +533,8 @@ public class ListUtils {
* @since 3.2
*/
public static <E> List<E> removeAll(final Collection<E> collection, final Collection<?> remove) {
+ Objects.requireNonNull(collection, "collection");
+ Objects.requireNonNull(remove, "remove");
final List<E> list = new ArrayList<>();
for (final E obj : collection) {
if (!remove.contains(obj)) {
diff --git a/src/test/java/org/apache/commons/collections4/ListUtilsTest.java b/src/test/java/org/apache/commons/collections4/ListUtilsTest.java
index b22f177ef..12d552584 100644
--- a/src/test/java/org/apache/commons/collections4/ListUtilsTest.java
+++ b/src/test/java/org/apache/commons/collections4/ListUtilsTest.java
@@ -369,6 +369,12 @@ public class ListUtilsTest {
assertThrows(NullPointerException.class, () -> ListUtils.removeAll(null, null),
"expecting NullPointerException");
+
+ assertThrows(NullPointerException.class, () -> ListUtils.removeAll(null, new ArrayList<Object>()),
+ "expecting NullPointerException");
+
+ assertThrows(NullPointerException.class, () -> ListUtils.removeAll(new ArrayList<Object>(), null),
+ "expecting NullPointerException");
}
@Test