8240626: Some of the java.time.chrono.Eras return empty display name for some styles and locales
Reviewed-by: joehw
This commit is contained in:
parent
e746891f96
commit
2b4b3d9efc
@ -286,7 +286,7 @@ class Bundle {
|
||||
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 @@ class Bundle {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 @@ class Bundle {
|
||||
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 @@ class Bundle {
|
||||
* 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 @@ class Bundle {
|
||||
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 java.util.stream.Stream;
|
||||
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 @@ public class TestEraDisplayName {
|
||||
.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 class TestEraDisplayName {
|
||||
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);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user