-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.2.0
-
generic
-
solaris_2.5.1
A licensee has reported unexpected behaviour with getBundle method.
For this test case you need :-
test.java
testRes.properties
testRes_de.properties
The unexpected behaviour in the test case is the second usage of getBundle.
At the second usage of getBundle the default locale is de_DE and getBundle
is called with a current locale of en_US. The expected behaviour is that the
en_US resource file is used but instead the de_DE resource bundle is used.
# cat > testRes_de.properties
k3 = datum von heute: {0, date}
# cat > testRes.properties
k3 = date of today: {0, date}
# java test en
First usage of getBundle: default locale=en_US
Second usage of getBundle: default locale=de_DE desired locale=en_US
getString returned english (testRes)
date of today: {0, date} <=== Correct
# java test de
First usage of getBundle: default locale=de_DE
Second usage of getBundle: default locale=de_DE desired locale=en_US
getString returned german (testRes_de)
datum von heute: {0, date} <== I asked for en_US
import java.util.Locale;
import java.util.ResourceBundle;
public class test {
public static void main (String[] args) {
String initialDefault;
ResourceBundle r;
if (args.length == 0)
initialDefault = "en";
else
initialDefault = args[0];
if (initialDefault.equals("en"))
Locale.setDefault(new Locale ("en", "US"));
else
Locale.setDefault(new Locale ("de", "DE"));
System.out.println("First usage of getBundle:" +
" default locale=" + Locale.getDefault());
r = ResourceBundle.getBundle ("testRes", Locale.getDefault());
Locale.setDefault( new Locale("de", "DE") );
Locale desired = new Locale("en", "US");
System.out.println("Second usage of getBundle:" +
" default locale=" + Locale.getDefault() +
" desired locale=" + desired.toString());
r = ResourceBundle.getBundle("testRes", desired );
String s = r.getString ("k3");
if (s.startsWith("date"))
System.out.println("getString returned english (testRes)");
else
System.out.println("getString returned german (testRes_de)");
System.out.println(s);
}
}
- duplicates
-
JDK-4120068 ResourceBundle falls back to default locale before root locale
-
- Closed
-