-
Bug
-
Resolution: Fixed
-
P3
-
1.4.0
-
beta2
-
x86, sparc
-
generic, linux, solaris_2.6, windows_2000
-
Verified
Name: auR10023 Date: 07/30/2001
java.util.ListResourceBundle.getKeys() doesn`t work with null keys.
The javadoc for this method says nothing about the difference between
null and non-null keys.
javadoc for ListResourceBundle:
...
getKeys
public Enumeration getKeys()
Implementation of ResourceBundle.getKeys.
Specified by:
getKeys in class ResourceBundle
...
javadoc for ResourceBundle:
...
getKeys
public abstract Enumeration getKeys()
Returns an enumeration of the keys.
...
But if null keys is used in ListResourceBundle this method returns empty
Enumeration.
Here is the example:
---------------t.java---------------
import java.util.*;
public class t {
public static void main(String argv[]) {
String key = null;
Object[][] contents1 = new Object[][] {{null, null}};
Object[][] contents2 = new Object[][] {{"k0", "v0"}};
ListResourceBundle parent =
new PrimitiveBundle(new Object[][] {{"k", "v"}});
System.out.println("Printing keys of bundle (It contains null keys)");
PrimitiveBundle bundle1 = new PrimitiveBundle(contents1, parent);
Enumeration e1 = bundle1.getKeys();
while (e1.hasMoreElements()) {
Object ne = e1.nextElement();
System.out.println(ne);
}
System.out.println("Printing keys of bundle (It contains non null keys)");
PrimitiveBundle bundle2 = new PrimitiveBundle(contents2, parent);
Enumeration e2 = bundle2.getKeys();
while (e2.hasMoreElements()) {
Object ne = e2.nextElement();
System.out.println(ne);
}
}
}
class PrimitiveBundle extends ListResourceBundle {
Object[][] list;
PrimitiveBundle(Object[][] list) {
this.list = list;
setParent(null);
}
PrimitiveBundle(Object[][] list, ListResourceBundle parent) {
this.list = list;
setParent(parent);
}
protected Object[][] getContents() {
return list;
}
}
------------------output:-------------
#java -version
java version "1.4.0-beta_refresh"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta_refresh-b69)
Java HotSpot(TM) Client VM (build 1.4.0-beta_refresh-b69, mixed mode)
#java t
Printing keys of bundle (It contains null keys)
Printing keys of bundle (It contains non null keys)
k0
k
======================================================================
- relates to
-
JDK-4475051 List/PropertyResourceBundle.handleGetObject(null) do not throw NPE
-
- Closed
-