Name: rmT116609 Date: 01/16/2003
FULL PRODUCT VERSION :
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.
A DESCRIPTION OF THE PROBLEM :
Nulls cannot be removed from TreeSet
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Add a null to a TreeSet.
2. Try to remove it.
3. Profit!!!!
EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected:
class java.util.HashSet
[null]
[]
class java.util.TreeSet
[null]
[]
Actual:
class java.util.HashSet
[null]
[]
class java.util.TreeSet
[null]
Exception in thread "main" java.lang.NullPointerException
at java.util.TreeMap.compare(TreeMap.java:1081)
at java.util.TreeMap.getEntry(TreeMap.java:341)
at java.util.TreeMap.remove(TreeMap.java:500)
at java.util.TreeSet.remove(TreeSet.java:218)
at Test.main(Test.java:17)
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.NullPointerException
at java.util.TreeMap.compare(TreeMap.java:1081)
at java.util.TreeMap.getEntry(TreeMap.java:341)
at java.util.TreeMap.remove(TreeMap.java:500)
at java.util.TreeSet.remove(TreeSet.java:218)
at Test.main(Test.java:17)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.*;
public class Test {
public static void main(String args[]) {
Set set = new HashSet();
System.out.println(set.getClass());
set.add(null);
System.out.println(set);
set.remove(null);
System.out.println(set);
set = new TreeSet();
System.out.println(set.getClass());
set.add(null);
System.out.println(set);
set.remove(null);
System.out.println(set);
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
set = new HashSet(set);
set.remove(null);
set = new TreeSet();
(Review ID: 164182)
======================================================================