JDK-7129551 : java.util.Locale backward compatibility break
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2012-01-12
  • Updated: 2012-03-20
  • Resolved: 2012-01-12
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
Java 7, update 1, update 2

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

A DESCRIPTION OF THE PROBLEM :
The introduction in Java 7 of Locale.Category has led to a serious backward compatibility problem.

I have an US English license of Windows XP running on my system, regionally configured as Italian (Switzerland).

With Java <= 1.6, System.out.println(Locale.getDefault()) gives "it_CH", which is correct.

Now Java 1.7 for the same command gives "en_US"; the same happens with System.out.println(Locale.getDefault(Locale.Category.DISPLAY))
(which I assume is the default value when calling the plain getDefault() method), while System.out.println(Locale.getDefault(Locale.Category.FORMAT))
produces "it_CH".

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Invoke

System.out.println(java.util.Locale.getDefault());

on two systems, one running Java 6 (or older) and the other running Java 7

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
java.util.Locale.getDefault() should return the regionally configured locale
ACTUAL -
java.util.Locale.getDefault() returns the system's locale, regardless of the regional settings

REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER SUBMITTED WORKAROUND :
Add code to my localized programs in order to determine the correct locale to use in a mixed java versions scenario, compile them with javac 1.7 with the -source and -target flags set to 1.6 (and tolerate the compiler warnings); something like:

Locale localeToUse;

if (System.getProperty("java.runtime.version").startsWith("1.7")) {
    localeToUse = Locale.getDefault(Locale.Category.FORMAT);
} else {
    localeToUse = Locale.getDefault();
}

Comments
WORK AROUND Explicitly give user's locale through system properties as java launcher arguments, e.g., "-Duser.language=it -Duser.country=CH"
12-01-2012

EVALUATION The behavior change is intentional as a result for fixing 4700857. With this change, Java apps that use Locale.getDefault() for getting localized strings in menus/buttons, etc. will now display those strings in the UI Language provided by Windows (in this case, US English).
12-01-2012