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

(coll) AbstractSet.removeAll implementation may lead to incorrect NullPointerExceptions

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 5.0
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:

      Description

      FULL PRODUCT VERSION :
      java version "1.5.0_02"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
      Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode, sharing)


      ADDITIONAL OS VERSION INFORMATION :
      Linux itppc27 2.4.19-4GB #1 Mon Aug 4 23:38:42 UTC 2003 i686 unknown

      A DESCRIPTION OF THE PROBLEM :
      Collection.removeAll may optionally throw NullPointerException:
       
      * @throws NullPointerException if this collection contains one or more
      * null elements and the specified collection does not support
      * null elements (optional).

      But it may *not* throw NullPointerException if the *specified* collection contains one or more null elements and *this* collection does not support null elements.


      The optimized implementation of removeAll in AbstractSet breaks this: for optimization may delegate to remove(Object), and that method may (depending on the concrete implementation) throw NullPointerException if passed 'null' (because the specification allows it here).

      Either the documentation for Collection is incorrect (and should also allow NullPointerException here); or the implementation in AbstractSet should be fixed (catch NullPointerException for 'null' and ignore it).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute the given code.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No NullPointerException (as the conditions given in the specification are not given).
      ACTUAL -
      NullPointerException (see below)


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.NullPointerException
              at java.util.TreeMap.compare(TreeMap.java:1093)
              at java.util.TreeMap.getEntry(TreeMap.java:347)
              at java.util.TreeMap.remove(TreeMap.java:506)
              at java.util.TreeSet.remove(TreeSet.java:223)
              at java.util.AbstractSet.removeAll(AbstractSet.java:143)
              at AbstractSetBug.main(AbstractSetBug.java:18)
      b

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.*;

      public class AbstractSetBug {
          public static void main(String[] args) {
              Set s = new TreeSet();
              s.add("ABC");
              s.add("DEF");

              Set r = new HashSet();
              r.add(null);
              s.removeAll(r);
          }
      }

      ---------- END SOURCE ----------
      ###@###.### 2005-04-04 17:23:43 GMT

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              gmanwanisunw Girish Manwani (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Imported:
                Indexed: