changeset 13517:8e126e1398ee

8219890: Calendar.getDisplayName() returns empty string for new Japanese Era on some locales Reviewed-by: lancea
author naoto
date Wed, 03 Apr 2019 04:22:36 +0100
parents d264b1318b82
children ee55428fe158
files src/share/classes/java/util/JapaneseImperialCalendar.java test/java/util/Calendar/JapaneseEraNameTest.java
diffstat 2 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/JapaneseImperialCalendar.java	Wed Apr 03 04:07:00 2019 +0100
+++ b/src/share/classes/java/util/JapaneseImperialCalendar.java	Wed Apr 03 04:22:36 2019 +0100
@@ -992,9 +992,11 @@
 
         String name = CalendarDataUtility.retrieveFieldValueName(getCalendarType(), field,
                                                                  fieldValue, style, locale);
-        // If the ERA value is null, then
+        // If the ERA value is null or empty, then
         // try to get its name or abbreviation from the Era instance.
-        if (name == null && field == ERA && fieldValue < eras.length) {
+        if ((name == null || name.isEmpty()) &&
+                field == ERA &&
+                fieldValue < eras.length) {
             Era era = eras[fieldValue];
             name = (style == SHORT) ? era.getAbbreviation() : era.getName();
         }
--- a/test/java/util/Calendar/JapaneseEraNameTest.java	Wed Apr 03 04:07:00 2019 +0100
+++ b/test/java/util/Calendar/JapaneseEraNameTest.java	Wed Apr 03 04:22:36 2019 +0100
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8202088 8207152 8217609
+ * @bug 8202088 8207152 8217609 8219890
  * @summary Test the localized Japanese new era name (May 1st. 2019-)
  *      is retrieved no matter CLDR provider contains the name or not.
  * @run main/othervm -Djava.locale.providers=CLDR JapaneseEraNameTest
@@ -49,8 +49,10 @@
             // temporarily. Will be fixed as part of JDK-8220020.
             // { LONG, JAPAN, "\u5143\u53f7" },
             { LONG, US,    "NewEra" },
+            { LONG, CHINA, "NewEra" },
             { SHORT,JAPAN, "\u5143\u53f7" },// NewEra
             { SHORT,US,    "NewEra" },
+            { SHORT,CHINA, "N" },
         };
 
     public static void main(String[] args) {