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-11-29
  • 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 Availability Release.

To download the current JDK release, click here.
JDK 10 JDK 8 JDK 9
10Fixed 8u152Fixed 9 b158Fixed
Related Reports
Relates :  
Relates :  
Relates :  
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. 
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.

The code introduced with the fix does not cope with the return values from 10.12.

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

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!

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.