-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.4.0
-
x86
-
windows_nt
java.util.HashSet add(Object o) when null is added twice it is accepted
in jdk1.4 build75.
And returns true.
As per spec. it is suppose to add once only and second time return false.
In jdk1.4 build74 program was passing.
---------------------------------
Also after null is added to hashSet returns true.
and followed by hashSet.contains(null) returns false now(must return true)
and hashSet.remove(null) returns false now(must return true)
---------------------------------------------------------------------
Following is the test program:
import java.util.*;
import java.io.*;
public class Add {
public static void main(String[] args) throws Exception {
AddTest01();
}
public static boolean AddTest01() {
boolean bReturn = false;
try {
HashSet hashSet = new HashSet();
if (!hashSet.add(null)) {
throw new Exception("!hashSet.add(null) not ok in AddTest01()");
}
if (hashSet.size() !=1) {
throw new Exception("(hashSet.size() !=1 not ok in AddTest01");
}
//add second time null must return false and size remain same
if (hashSet.add(null)) {
throw new Exception("hashSet.add(null) not ok in AddTest01()");
}
bReturn = true;
System.out.println("AddTest01() Pass");
} catch(Exception e) {
bReturn = false;
System.out.println("Exception thrown = " + e);
System.out.println("AddTest01() Fail");
e.printStackTrace();
}
return bReturn;
}
}
------------------------contains() and remove()--------------------------------
hashSet.add(null) returns true
hashSet.contains(null) returns false
hashSet.remove(null) retunrs false.
------------------------------------------------------------------------------
in jdk1.4 build75.
And returns true.
As per spec. it is suppose to add once only and second time return false.
In jdk1.4 build74 program was passing.
---------------------------------
Also after null is added to hashSet returns true.
and followed by hashSet.contains(null) returns false now(must return true)
and hashSet.remove(null) returns false now(must return true)
---------------------------------------------------------------------
Following is the test program:
import java.util.*;
import java.io.*;
public class Add {
public static void main(String[] args) throws Exception {
AddTest01();
}
public static boolean AddTest01() {
boolean bReturn = false;
try {
HashSet hashSet = new HashSet();
if (!hashSet.add(null)) {
throw new Exception("!hashSet.add(null) not ok in AddTest01()");
}
if (hashSet.size() !=1) {
throw new Exception("(hashSet.size() !=1 not ok in AddTest01");
}
//add second time null must return false and size remain same
if (hashSet.add(null)) {
throw new Exception("hashSet.add(null) not ok in AddTest01()");
}
bReturn = true;
System.out.println("AddTest01() Pass");
} catch(Exception e) {
bReturn = false;
System.out.println("Exception thrown = " + e);
System.out.println("AddTest01() Fail");
e.printStackTrace();
}
return bReturn;
}
}
------------------------contains() and remove()--------------------------------
hashSet.add(null) returns true
hashSet.contains(null) returns false
hashSet.remove(null) retunrs false.
------------------------------------------------------------------------------
- duplicates
-
JDK-4491429 HashMap regression with key value null
- Closed