JDK-8046419 : getLocale() api works differently with JDK 7
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7
  • Priority: P2
  • Status: Resolved
  • Resolution: Not an Issue
  • Submitted: 2014-06-10
  • Updated: 2014-07-22
  • Resolved: 2014-07-22
Related Reports
Relates :  
Description
If you open "Region and Language" applet in Windows Control Panel and set Format to "Arabic (U.A.E.)", then Applet.getLocale() and Locale.getDefault() return "en_US" in JDK 7+. With JDK 6, those calls return "ar_AE" as expected.
Comments
I attached the minimal test case: LocaleTest.java. If you open "Region and Language" applet in Windows Control Panel and set Format to "Arabic (U.A.E.)", then on Windows with English UI you will see: C:\test>java LocaleTest Display locale: en_US Format locale: ar_AE Default locale: en_US If you run LocaleTest class in the same environment with property sun.locale.formatasdefault=true, you will see: C:\test>java -Dsun.locale.formatasdefault=true LocaleTest Display locale: en_US Format locale: ar_AE Default locale: ar_AE If you switch Windows UI to Spanish, the output will change: C:\test>java LocaleTest Display locale: es_ES Format locale: ar_AE Default locale: es_ES In all of the above cases, JDK 6 output is: Default locale: ar_AE To compile LocaleTest.java with JDK 6, remove import of Locale.Category and output of Locales with categories.
22-07-2014

It is not a bug, it is a new feature of JDK 7 with enhanced locale support. JDK 7 provides additional locale API to distinguish display language and formatting parameters: Locale.getDefault(Locale.Category.DISPLAY) Locale.getDefault(Locale.Category.FORMAT) DISPLAY category corresponds to the UI language of the OS. If you start a Java app on Windows with English UI, Locale.getDefault(Locale.Category.DISPLAY) will return "en_US". If you switch Windows UI to Spanish, for example, it will return "es_ES". So your Java application can "speak" the same language as the OS. FORMAT category corresponds to the regional formatting settings, for example formats of date and time. By default, on English version of Windows, Formats are set to English (United States), thus Locale.getDefault(Locale.Category.FORMAT) returns "en_US". If you change this setting to "Arabic (U.A.E.)", Locale.getDefault(Locale.Category.FORMAT) will return "ar_AE". Locale.getDefault() is preserved for backwards compatibility, and it defaults to Locale.getDefault(Locale.Category.DISPLAY). JDK 6 had only Locale.getDefault() and the returned locale corresponded to Formatting settings. To get the previous behavior in JDK 7, set "sun.locale.formatasdefault" system property to "true". After default locale is initialized, changing this property has no effect. To get the predictable behavior, set this property on the JVM command line. These incompatibilities are described in the JDK 7 Release Notes: http://www.oracle.com/technetwork/java/javase/compatibility-417013.html#incompatibilities Quote: Area: API: Internationalization Synopsis: Separation of User Locale and User Interface Locale Description: The default locale can be independently set for two types of uses: the format setting is used for formatting resources, and the display setting is used in menus and dialogs. The new Locale.getDefault(Locale.Category) method takes a Locale.Category parameter. Previous behavior can be restored by setting the sun.locale.formatasdefault system property to true. Nature of Incompatibility: behavioral RFE: 4700857 This feature is also described in "Internationalization Enhancements in Java SE 7" document http://docs.oracle.com/javase/7/docs/technotes/guides/intl/enhancements.7.html, see "Category Locale Support" section http://docs.oracle.com/javase/7/docs/technotes/guides/intl/enhancements.7.html#category. This document can be accessed from http://www.oracle.com/technetwork/java/javase/jdk7-relnotes-418459.html "Java SE 7 Features and Enhancements".
22-07-2014