changeset 60494:500f99ff1921

8240626: Some of the java.time.chrono.Eras return empty display name for some styles and locales Reviewed-by: joehw
author naoto
date Mon, 16 Mar 2020 09:26:01 -0700
parents d25079af1459
children 42b62267498d a4e2fc916323
files make/jdk/src/classes/build/tools/cldrconverter/Bundle.java test/jdk/java/time/test/java/time/chrono/TestEraDisplayName.java
diffstat 2 files changed, 40 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/make/jdk/src/classes/build/tools/cldrconverter/Bundle.java	Mon Mar 16 22:43:44 2020 +0800
+++ b/make/jdk/src/classes/build/tools/cldrconverter/Bundle.java	Mon Mar 16 09:26:01 2020 -0700
@@ -286,7 +286,7 @@
             handleMultipleInheritance(myMap, parentsMap, calendarPrefix + "QuarterAbbreviations");
             handleMultipleInheritance(myMap, parentsMap, calendarPrefix + "QuarterNarrows");
 
-            adjustEraNames(myMap, calendarType);
+            adjustEraNames(myMap, parentsMap, calendarType);
 
             handleDateTimeFormatPatterns(TIME_PATTERN_KEYS, myMap, parentsMap, calendarType, "TimePatterns");
             handleDateTimeFormatPatterns(DATE_PATTERN_KEYS, myMap, parentsMap, calendarType, "DatePatterns");
@@ -410,8 +410,9 @@
     }
 
     /**
-     * Fills in any empty elements with its parent element. Returns true if the resulting array is
-     * identical to its parent array.
+     * Fills in any empty elements with its parent element, falling back to
+     * aliased one if parent element is not found. Returns true if the resulting
+     * array is identical to its parent array.
      *
      * @param parents
      * @param key
@@ -423,7 +424,7 @@
             return false;
         }
         if (value instanceof String[]) {
-            Object pvalue = parents.get(key);
+            Object pvalue = parents.getOrDefault(key, parents.get(CLDRConverter.aliases.get(key)));
             if (pvalue != null && pvalue instanceof String[]) {
                 String[] strings = (String[]) value;
                 String[] pstrings = (String[]) pvalue;
@@ -442,7 +443,7 @@
      * Adjusts String[] for era names because JRE's Calendars use different
      * ERA value indexes in the Buddhist, Japanese Imperial, and Islamic calendars.
      */
-    private void adjustEraNames(Map<String, Object> map, CalendarType type) {
+    private void adjustEraNames(Map<String, Object> map, Map<String, Object> pMap, CalendarType type) {
         String[][] eraNames = new String[ERA_KEYS.length][];
         String[] realKeys = new String[ERA_KEYS.length];
         int index = 0;
@@ -450,6 +451,9 @@
             String realKey = type.keyElementName() + key;
             String[] value = (String[]) map.get(realKey);
             if (value != null) {
+                // first fill in missing elements from parents map.
+                fillInElements(pMap, realKey, value);
+
                 switch (type) {
                 case GREGORIAN:
                     break;
--- a/test/jdk/java/time/test/java/time/chrono/TestEraDisplayName.java	Mon Mar 16 22:43:44 2020 +0800
+++ b/test/jdk/java/time/test/java/time/chrono/TestEraDisplayName.java	Mon Mar 16 09:26:01 2020 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -35,13 +35,14 @@
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
 
 /**
  * Tests Era.getDisplayName() correctly returns the name based on each
  * chrono implementation.
  * Note: The exact result may depend on locale data provider's implementation.
  *
- * @bug 8171049 8224105
+ * @bug 8171049 8224105 8240626
  */
 @Test
 public class TestEraDisplayName {
@@ -150,6 +151,19 @@
             .toArray(Object[][]::new);
     }
 
+    @DataProvider
+    Object[][] allEras() {
+        return Stream.of(IsoEra.values(),
+                        JapaneseEra.values(),
+                        HijrahEra.values(),
+                        ThaiBuddhistEra.values(),
+                        MinguoEra.values())
+            .flatMap(v -> Arrays.stream(v))
+            .map(Stream::of)
+            .map(Stream::toArray)
+            .toArray(Object[][]::new);
+    }
+
     @Test(dataProvider="eraDisplayName")
     public void test_eraDisplayName(Era era, TextStyle style, Locale locale, String expected) {
         assertEquals(era.getDisplayName(style, locale), expected);
@@ -160,4 +174,19 @@
         DateTimeFormatter f = JAPANESE_FORMATTER.withLocale(locale);
         assertEquals(LocalDate.parse(REIWA_1ST.format(f), f), REIWA_1ST);
     }
+
+    // Make sure era display names aren't empty
+    // @bug 8240626
+    @Test(dataProvider="allEras")
+    public void test_noEmptyEraNames(Era era) {
+        Arrays.stream(Locale.getAvailableLocales())
+            .forEach(l -> {
+                Arrays.stream(TextStyle.values())
+                    .forEach(s -> {
+                        assertFalse(era.getDisplayName(s, l).isEmpty(),
+                            "getDisplayName() returns empty display name for era: " + era
+                            + ", style: " + s + ", locale: " + l);
+                    });
+            });
+    }
 }