JDK-8174779 : Locale issues with Mac 10.12
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • CPU: x86
  • Submitted: 2017-02-10
  • Updated: 2017-07-05
  • Resolved: 2017-02-14
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 Availabitlity Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u152Resolved 9 b158Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
With Mac 10.12 there are some locale issues with Simplified and traditional chinese. 
Locale.getDefault() returns zh-hans-us / zh-hant-us for the above languages
The above causes some issues when we format a date instance. 

Date currentDate = new Date();
String date = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault()).format(currentDate);

The above code throws an exception "ill-fomed language: zh-hans-us" for simplified chinese - Mac 10.12 and JDK9 b 155

These languages were earlier handled as zh_TW/zh_CN 

Also if run as a standalone java class, DateFormat.MEDIUM does not show any Chinese characters, DateFormat.LONG shows Chinese characters. 
Comments
Looks like from macOS 10.12, the primary language returned from CFLocaleCopyPreferredLanguages() includes both region and script in some cases, such as in this scenario. In this case, it returns zh-Hans-US which cannot be parsed correctly, and all got into user.language property.
2017-02-13

The code introduced with the fix does not cope with the return values from 10.12.
2017-02-13

In JDK8 they were handled as zh_TW/zh_CN In jdk9 as far as I can test, it's been zh-hans-<Country> for Mac 10.12. I just tested for jdk9 - b 156 in 10.9 machine and there it shows default locale as zh_CN
2017-02-13

Hi Vivek, >These languages were earlier handled as zh_TW/zh_CN Do you know the last build that resulted in zh_TW/CN? If so, please add that info to this issue. Thanks!
2017-02-13

Attached a sample Solution.java file that can be used to see the issue. You will need to change the locale to Simplified / Traditional Chinese to see the output. Also the code in deploy - deploy/src/jdk.deploy.controlPanel/share/classes/com/sun/deploy/jcp/controller/General.java (Has a DateFormat) which throws the exception as mentioned in the bug.
2017-02-11