United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7073906 Locale.getDefault() returns wrong Locale for Java SE 7
JDK-7073906 : Locale.getDefault() returns wrong Locale for Java SE 7

Details
Type:
Bug
Submit Date:
2011-08-02
Status:
Resolved
Updated Date:
2012-10-01
Project Name:
JDK
Resolved Date:
2011-09-07
Component:
core-libs
OS:
windows_vista,windows_xp,windows_7,windows
Sub-Component:
java.util:i18n
CPU:
x86,generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Backport:
Duplicate:
Relates:

Sub Tasks

Description
FULL PRODUCT VERSION :
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
Microsoft Windows [Version 6.1.7600]

EXTRA RELEVANT SYSTEM CONFIGURATION :
Locale on Windows is set to "English (United Kingdom)" under "standards and formats" and "Language for non-Unicode programs".  Location is set to "United Kingdom"

A DESCRIPTION OF THE PROBLEM :
The Locale returned from Locale.getDefault() is en_US when it shoud be en_GB

This goes wrong on switching to version 1.7.0.  Running the same software on the same environment under 1.6.0_26 and earlier it worked as expected.

The result is that all the Locale specific output of times and dates in our software comes out wrong for our UK customers - today is 8/2/11 when it should be 02/08/11 etc

REGRESSION.  Last worked in version 6u26

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Set all the locale settings under Windows to "English (United Kingdom)".  I have tried this on both Windows XP and Windows 7

Run this code and compare the results for 1.6 and 1.7:

System.out.println("java.version = " + System.getProperty("java.version"));
System.out.println("Locale.getDefault() = " + Locale.getDefault());

My output:

>"C:\Program Files\Java\jre6\bin\java" nonguitestrig.Main
java.version = 1.6.0_26
Locale.getDefault() = en_GB

>"C:\Program Files\Java\jre7\bin\java" nonguitestrig.Main
java.version = 1.7.0
Locale.getDefault() = en_US


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The call should return the Locale set in the OS as it did under 1.6, i.e. en_GB
ACTUAL -
Java 1.7 returns a different result to 1.6, en_US

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.Locale;

public class Main {
    public static void main(String[] args) {
		System.out.println("java.version = " + System.getProperty("java.version"));
		System.out.println("Locale.getDefault() = " + Locale.getDefault());
    }
}
---------- END SOURCE ----------

                                    

Comments
EVALUATION

The change was intentional as the result of the new feature 4700857, where the default locale is now derived from the DISPLAY locale. On Windows, it is derived from the user's UI Language.

However, the Windows Control Panel only allows users to select "language" without any region information for the UI Language in its selection menu. For example there is only one selection "English" for all English locales. To remedy this situation, if the language portion of UI language and the user locale (the "Format" locale) are the same, UI Language's region information will now be replaced with the one in the "Format" locale.
                                     
2011-08-16



Hardware and Software, Engineered to Work Together