some methods in java.util.Collections don't throw NPE when the parameter is
null
---------------------------------------------------------------------------------
Key: ADDR-13
URL: http://issues.apache.org/jira/browse/ADDR-13
Project: Addressing
Type: Bug
Reporter: Svetlana Samoilenko
According to j2se 1.4.2 and 1.5 specification for the Collections class "The
methods of this class all throw a NullPointerException if the collections
provided to them are null".
Harmony does not throw NPE for some methods.
Code to reproduce:
import java.util.*;
public class test2 {
public static void main(String [] args) {
SortedMap m = null;
Map map=null;
Set set=null;
SortedSet sortedset=null;
SortedMap sortedmap =null;
Collection col=null;
try {
Collections.synchronizedCollection(col);
System.out.println("synchronizedCollection(null) must throw
NPE");
} catch (NullPointerException e) {
System.out.println("PASSED");
}
try {
Collections.synchronizedSortedMap(sortedmap);
System.out.println("synchronizedSortedMap(null) must throw NPE");
} catch (NullPointerException e) {
System.out.println("PASSED");
}
try {
Collections.synchronizedMap(map);
System.out.println("synchronizedMap(map) must throw NPE");
} catch (NullPointerException e) {
System.out.println("PASSED");
}
try {
Collections.synchronizedSet(set);
System.out.println("synchronizedSet(set) must throw NPE");
} catch (NullPointerException e) {
System.out.println("PASSED");
}
try {
Collections.synchronizedSortedSet(sortedset);
System.out.println("synchronizedSortedSet(null) must throw
NPE");
} catch (NullPointerException e) {
System.out.println("PASSED");
}
try {
Collections.unmodifiableCollection(col);
System.out.println("unmodifiableCollection(null) must throw
NPE");
} catch (NullPointerException e) {
System.out.println("PASSED");
}
try {
Collections.unmodifiableMap(map);
System.out.println("unmodifiableMap(null) must throw NPE");
} catch (NullPointerException e) {
System.out.println("PASSED");
}
try {
Collections.unmodifiableSet(set);
System.out.println("unmodifiableSet(null) must throw NPE");
} catch (NullPointerException e) {
System.out.println("PASSED");
}
try {
Collections.unmodifiableSortedMap(sortedmap);
System.out.println("unmodifiableSortedMap(null) must throw
NPE");
} catch (NullPointerException e) {
System.out.println("PASSED");
}
try {
Collections.unmodifiableSortedSet(sortedset);
System.out.println("unmodifiableSortedSet(null) must throw
NPE");
} catch (NullPointerException e) {
System.out.println("PASSED");
}
}
}
Steps to Reproduce:
1. Build Harmony (check-out on 2006-01-30) j2se subset as described in
README.txt.
2. Compile test2.java using BEA 1.4 javac
> javac -d . test2.java
3. Run java using compatible VM (J9)
> java -showversion test2
Output:
C:\tmp>C:\jrockit-j2sdk1.4.2_04\bin\java.exe -showversion test2
java version "1.4.2_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
BEA WebLogic JRockit(TM) 1.4.2_04 JVM (build ari-31788-20040616-1132-win-ia32,
Native Threads, GC strategy: parallel)
PASSED
PASSED
PASSED
PASSED
PASSED
PASSED
PASSED
PASSED
PASSED
PASSED
C:\tmp>C:\harmony\trunk\deploy\jre\bin\java -showversion test2
(c) Copyright 1991, 2005 The Apache Software Foundation or its licensors, as
applicable.
synchronizedCollection(null) must throw NPE
synchronizedSortedMap(null) must throw NPE
synchronizedMap(map) must throw NPE
synchronizedSet(set) must throw NPE
synchronizedSortedSet(null) must throw NPE
unmodifiableCollection(null) must throw NPE
unmodifiableMap(null) must throw NPE
unmodifiableSet(null) must throw NPE
unmodifiableSortedMap(null) must throw NPE
unmodifiableSortedSet(null) must throw NPE
Suggected fix and test in attachment.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]