changeset 17737:125e348a3cbf

8180469: Wrong short form text for supplemental Japanese era Reviewed-by: rriggs
author naoto
date Thu, 31 Aug 2017 08:35:16 -0700
parents 5a28f7ef36da
children 10498d6923ae cd9b04ac647e
files src/java.base/share/classes/sun/util/locale/provider/CalendarNameProviderImpl.java test/java/util/Calendar/SupplementalJapaneseEraTest.java
diffstat 2 files changed, 16 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/sun/util/locale/provider/CalendarNameProviderImpl.java	Wed Aug 30 12:46:53 2017 -0700
+++ b/src/java.base/share/classes/sun/util/locale/provider/CalendarNameProviderImpl.java	Thu Aug 31 08:35:16 2017 -0700
@@ -87,9 +87,15 @@
                         Era[] jeras = CalendarSystem.forName("japanese").getEras();
                         if (jeras.length == value) {
                             Era supEra = jeras[value - 1]; // 0-based index
-                            return style == LONG ?
-                                supEra.getName() :
-                                supEra.getAbbreviation();
+                            if (javatime) {
+                                return getBaseStyle(style) == NARROW_FORMAT ?
+                                    supEra.getAbbreviation() :
+                                    supEra.getName();
+                            } else {
+                                return (style & LONG) != 0 ?
+                                    supEra.getName() :
+                                    supEra.getAbbreviation();
+                            }
                         }
                     }
                     return null;
--- a/test/java/util/Calendar/SupplementalJapaneseEraTest.java	Wed Aug 30 12:46:53 2017 -0700
+++ b/test/java/util/Calendar/SupplementalJapaneseEraTest.java	Thu Aug 31 08:35:16 2017 -0700
@@ -25,7 +25,7 @@
 import java.time.chrono.JapaneseChronology;
 import java.time.chrono.JapaneseDate;
 import java.time.chrono.JapaneseEra;
-import java.time.format.DateTimeFormatterBuilder;
+import java.time.format.DateTimeFormatter;
 import java.time.format.TextStyle;
 import java.util.Calendar;
 import java.util.Date;
@@ -166,17 +166,15 @@
             errors++;
         }
 
-        // test long/abbreviated names with java.time.format
-        got = new DateTimeFormatterBuilder()
-            .appendPattern("GGGG")
-            .appendLiteral(" ")
-            .appendPattern("G")
-            .toFormatter(Locale.US)
+        // test full/short/narrow names with java.time.format
+        got = DateTimeFormatter
+            .ofPattern("GGGG G GGGGG")
+            .withLocale(Locale.US)
             .withChronology(JapaneseChronology.INSTANCE)
             .format(jdate);
-        expected = NEW_ERA_NAME + " " + NEW_ERA_ABBR;
+        expected = NEW_ERA_NAME + " " + NEW_ERA_NAME + " " + NEW_ERA_ABBR;
         if (!expected.equals(got)) {
-            System.err.printf("java.time formatter long/abbr names: got=\"%s\", expected=\"%s\"%n", got, expected);
+            System.err.printf("java.time formatter full/short/narrow names: got=\"%s\", expected=\"%s\"%n", got, expected);
             errors++;
         }
     }