8180469: Wrong short form text for supplemental Japanese era
authornaoto
Thu, 31 Aug 2017 08:35:16 -0700
changeset 47030 d548b7a9ba3e
parent 47029 7d0ceae2dec2
child 47031 78fb24b5f758
child 47193 b12ec990a6b1
8180469: Wrong short form text for supplemental Japanese era Reviewed-by: rriggs
jdk/src/java.base/share/classes/sun/util/locale/provider/CalendarNameProviderImpl.java
jdk/test/java/util/Calendar/SupplementalJapaneseEraTest.java
--- a/jdk/src/java.base/share/classes/sun/util/locale/provider/CalendarNameProviderImpl.java	Wed Aug 30 12:46:53 2017 -0700
+++ b/jdk/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/jdk/test/java/util/Calendar/SupplementalJapaneseEraTest.java	Wed Aug 30 12:46:53 2017 -0700
+++ b/jdk/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++;
         }
     }