-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.3.0
-
x86
-
linux
Name: yyT116575 Date: 12/13/2000
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)
When I run any Java program, no matter what I set the system properties
user.language and user.region to, the default locale is still en_US. Here is
an example program:
import java.util.*;
public class LocaleBug {
public static void main(String[] args) {
for (Iterator iter = System.getProperties().keySet().iterator();iter.hasNext(); ) {
String key = (String) iter.next();
if (key.startsWith("user.") || key.startsWith("java.vm.")) {
System.out.println(key + " -> " + System.getProperty(key));
}
}
System.out.println("locale is " + Locale.getDefault());
}
}
Here is what happens when I run it with the 3 VMs on my system:
[john@localhost ~/projects/filler/locale]$ /opt/jbuilder4/jdk1.3/bin/java
-Duser.language=fr -Duser.region=FR LocaleBug
java.vm.version -> 1.3.0
java.vm.vendor -> IBM Corporation
java.vm.name -> Classic VM
java.vm.specification.name -> Java Virtual Machine Specification
user.dir -> /home/john/projects/filler/locale
java.vm.specification.vendor -> Sun Microsystems Inc.
user.home -> /home/john
user.timezone -> Pacific/Honolulu
user.name -> john
java.vm.specification.version -> 1.0
user.language -> fr
java.vm.info -> J2RE 1.3.0 IBM build cx130-20000815 (JIT enabled: jitc)
user.region -> FR
locale is fr_FR
[john@localhost ~/projects/filler/locale]$ /opt/IBMJava2-13/jre/bin/java
-Duser.language=fr -Duser.region=FR LocaleBug
java.vm.version -> 1.3.0
java.vm.vendor -> IBM Corporation
java.vm.name -> Classic VM
java.vm.specification.name -> Java Virtual Machine Specification
user.dir -> /home/john/projects/filler/locale
java.vm.specification.vendor -> Sun Microsystems Inc.
user.home -> /home/john
user.timezone -> Pacific/Honolulu
user.name -> john
java.vm.specification.version -> 1.0
user.language -> fr
java.vm.info -> J2RE 1.3.0 IBM build cx130-20000623 (JIT enabled: jitc)
user.region -> FR
locale is fr_FR
[john@localhost ~/projects/filler/locale]$ /usr/java/jdk1.3/bin/java
-Duser.language=fr -Duser.region=FR LocaleBug
java.vm.version -> 1.3.0
java.vm.vendor -> Sun Microsystems Inc.
java.vm.name -> Java HotSpot(TM) Client VM
java.vm.specification.name -> Java Virtual Machine Specification
user.dir -> /home/john/projects/filler/locale
java.vm.specification.vendor -> Sun Microsystems Inc.
user.home -> /home/john
user.timezone ->
user.name -> john
java.vm.specification.version -> 1.0
user.language -> fr
java.vm.info -> mixed mode
user.region -> FR
locale is en_US
As you can see, the Sun VM knows the correct language and region, and the locale
is wrong. I am guessing that the static initialiser for locale is run before the
values of the system variables are set????? The code in Locale.java is:
static {
String language =
(String) AccessController.doPrivileged(
new GetPropertyAction("user.language","EN"));
String country =
(String) AccessController.doPrivileged(
new GetPropertyAction("user.region",""));
/* The user.region property may be of the form country, country_variant,
* or _variant. Since the Locale constructor takes the country value as
* an unparsed literal, and we don't want to change that behavior, we
* must premunge it here into country and variant. - liu 7/24/98 */
String variant = "";
int i = country.indexOf('_');
if (i >= 0) {
variant = country.substring(i+1);
country = country.substring(0, i);
}
defaultLocale = new Locale(language, country, variant);
}
which suggests that what I think should work is correct, it just doesn't.
(Review ID: 113552)
======================================================================
- duplicates
-
JDK-4152725 Locales specified via command line not recognized
- Resolved
- relates to
-
JDK-4127375 Locale.getDefault() and user.language property
- Closed