Skip to content
Permalink
Browse files
8240626: Some of the java.time.chrono.Eras return empty display name …
…for some styles and locales

Reviewed-by: joehw
  • Loading branch information
naotoj committed Mar 16, 2020
1 parent e746891 commit 2b4b3d9efcf858f3368465da86c699c3bc69be84
Showing with 40 additions and 7 deletions.
  1. +9 −5 make/jdk/src/classes/build/tools/cldrconverter/Bundle.java
  2. +31 −2 test/jdk/java/time/test/java/time/chrono/TestEraDisplayName.java
@@ -286,7 +286,7 @@ String getCurrencies() {
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 @@ private void handleMultipleInheritance(Map<String, Object> map, Map<String, Obje
}

/**
* 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 @@ private boolean fillInElements(Map<String, Object> parents, String key, Object v
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,14 +443,17 @@ private boolean fillInElements(Map<String, Object> parents, String key, Object v
* 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;
for (String key : ERA_KEYS) {
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;
@@ -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 @@ public void test_reiwaNames(Locale locale) throws DateTimeParseException {
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);
});
});
}
}

0 comments on commit 2b4b3d9

Please sign in to comment.