[COLLECTIONS-814] CollectionUtils.removeAll() not throwing proper NullPointerException(NPE) if the first parameter is empty
Add null check
This commit is contained in:
parent
06cc4554b5
commit
17bed2b555
|
@ -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)) {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue