Details
-
Bug
-
Resolution: Fixed
-
P4
-
1.4.1
-
b91
-
x86
-
windows_2000
-
Verified
Description
Name: nt126004 Date: 01/13/2003
FULL PRODUCT VERSION :
java version "1.4.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)
FULL OPERATING SYSTEM VERSION : Microsoft Windows 2000
[Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
java.util.AbstractCollection.retainAll and removeAll
methods do not - as specified - throw a
NullPointerException when the argument is null.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create a non-abstract extension C of
java.util.AbstractCollection, not overriding the methods
removeAll or retainAll.
2. Create an instance X of C.
3. Invoke removeAll(null) on X.
4. Invoke retainAll(null) on X.
EXPECTED VERSUS ACTUAL BEHAVIOR :
Steps 3 and 4 should result in NullPointerExceptions
(according to the API specification). They don't.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.AbstractCollection;
import java.util.Iterator;
import java.util.ArrayList;
public class C extends AbstractCollection {
ArrayList list = new ArrayList();
public boolean remove(Object obj) {
return list.remove(obj);
}
public boolean add(Object obj) {
return list.add(obj);
}
public Iterator iterator() {
return list.iterator();
}
public int size() {
return list.size();
}
public static void main(String[] args) {
// Should throw NullPointerException
(new C()).removeAll(null);
// Should throw NullPointerException
(new C()).retainAll(null);
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
removeAll() and retainAll() should always be overridden.
(Review ID: 179274)
======================================================================
Attachments
Issue Links
- relates to
-
JDK-7123424 (coll) CopyOnWriteArrayList/CopyOnWriteArraySet don't throw NPE for removeAll(null)/retainAll(null)
- Resolved
-
JDK-8159404 throw UnsupportedOperationException unconditionally for mutator methods
- Resolved
-
JDK-8015656 (coll) unexpected NPE from removeAll causes JavaFX 8 build failure
- Closed
-
JDK-8021591 Additional NPE checks
- Closed