Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4802647

(coll) NullPointerException not thrown by AbstractCollection.retainAll/removeAll

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 8
    • 1.4.1
    • core-libs
    • 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

          Activity

            People

              mduigou Mike Duigou
              nthompsosunw Nathanael Thompson (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: