JDK-4802647 : (coll) NullPointerException not thrown by AbstractCollection.retainAll/removeAll
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 1.4.1
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-01-14
  • Updated: 2017-05-16
  • Resolved: 2013-05-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8 b91Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
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) 
======================================================================

Comments
verified in b94
17-06-2013

SUGGESTED FIX http://cr.openjdk.java.net/~mduigou/4802647/0/webrev/
19-11-2011

EVALUATION This is worth fixing, though not urgent. ###@###.### 2003-01-14
14-01-2003