JDK-8216204 : Wrong SimpleDateFormat behavior with Japanese Imperial Calendar
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 12
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2019-01-04
  • Updated: 2019-01-07
  • Resolved: 2019-01-07
Related Reports
Relates :  
Description
A DESCRIPTION OF THE PROBLEM :
I have tested New Era for Japanese Imperial Calendar.
In Java 8, the letter "G" indicates a short or abbreviated form like "H" (for Heisei Era).
But, after Java 9 (through 12-ea), the letter "G" indicates the full form like "������������".

REGRESSION : Last worked in version 8u192

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute below source code with JShell

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
H31.01.04
ACTUAL -
������������31.01.04

---------- BEGIN SOURCE ----------
import java.text.*;
Locale locale = new Locale("ja", "JP", "JP");
DateFormat alphabetFormat = new SimpleDateFormat("Gyy.MM.dd", locale);
Calendar now = Calendar.getInstance(locale);
System.out.println(alphabetFormat.format(now.getTime()));

---------- END SOURCE ----------

FREQUENCY : always



Comments
Thank you for the confirmation and the documentation. it's interesting that the short form of Heisei is ������ in CLDR :) I could understand why this occur and the workaround anyway. Regards
07-01-2019

Thanks for the clarification Shinya. From JDK 9 onwards, the default locale data is the data derived from the Unicode Consortium's Common Locale Data Repository (CLDR). Please refer https://www.unicode.org/cldr/charts/33/by_type/date_&_time.japanese.html The short display format for Heisei is ������ in the ja locale in CLDR data. Hence the difference in the result. To use the JRE locale with JDK 9 set java.locale.providers to a value with COMPAT ahead of CLDR. : -Djava.locale.providers=COMPAT, CLDR JDK 9 release notes reference: http://www.oracle.com/technetwork/java/javase/9-relnote-issues-3704069.html#JDK-8008577
07-01-2019

Hi Pallavi, I'm not a reporter of this issue. but as a Japanese, let me add more detail about this issue. This is not a NewEra issue, a breaking backward compatibility issue of JDK API. If JDK is <= 8, SimpleDateFormat print short form of JapaneseEra(like 'S' for Showa, 'H' for Heisei) for 'G', 'GG', 'GGG' format. However, after JDK 10(I'm not sure how it works in JDK 9), SimpleDateFormat print long(full) form of JapaneseEra(like Showa, Heisei) for 'G' format and so on. For more detail, please see the screenshot which is attached above. In the former case, JDK 8 prints 'H31.01.07'. However, JDK 10 prints '������31.01.07'('Heisei31.01.07') in the latter execution for the same program.
07-01-2019

Thank you!
07-01-2019

Reopening to analyze
07-01-2019