JDK-7073906 : Locale.getDefault() returns wrong Locale for Java SE 7
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 7
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS:
    windows,windows_xp,windows_vista,windows_7 windows,windows_xp,windows_vista,windows_7
  • CPU: generic,x86
  • Submitted: 2011-08-02
  • Updated: 2012-10-01
  • Resolved: 2011-09-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8
7u4Fixed 8 b04Fixed
Related Reports
Duplicate :  
Relates :  
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.
16-08-2011