8224105: Cannot parse JapaneseDate string on some specified locales

Reviewed-by: bchristi
This commit is contained in:
Naoto Sato 2019-05-21 13:40:56 -07:00
parent 94619467c8
commit 8f1d837e99
2 changed files with 25 additions and 2 deletions

View File

@ -257,11 +257,13 @@ public class CalendarNameProviderImpl extends CalendarNameProvider implements Av
return langtags;
}
// Check if each string is unique, except null or empty strings,
// as these strings are used for keys in the name-to-value map.
private boolean hasDuplicates(String[] strings) {
int len = strings.length;
for (int i = 0; i < len - 1; i++) {
String a = strings[i];
if (a != null) {
if (a != null && !a.isEmpty()) {
for (int j = i + 1; j < len; j++) {
if (a.equals(strings[j])) {
return true;

View File

@ -28,7 +28,9 @@ package test.java.time.chrono;
import java.time.*;
import java.time.chrono.*;
import java.time.format.*;
import java.util.Arrays;
import java.util.Locale;
import java.util.stream.Stream;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@ -39,13 +41,18 @@ import static org.testng.Assert.assertEquals;
* chrono implementation.
* Note: The exact result may depend on locale data provider's implementation.
*
* @bug 8171049
* @bug 8171049 8224105
*/
@Test
public class TestEraDisplayName {
private static final Locale THAI = Locale.forLanguageTag("th-TH");
private static final Locale EGYPT = Locale.forLanguageTag("ar-EG");
private static final LocalDate REIWA_1ST = LocalDate.of(2019, 5, 1);
private static final DateTimeFormatter JAPANESE_FORMATTER =
DateTimeFormatter.ofPattern("yyyy MM dd GGGG G GGGGG")
.withChronology(JapaneseChronology.INSTANCE);
@DataProvider(name="eraDisplayName")
Object[][] eraDisplayName() {
return new Object[][] {
@ -135,8 +142,22 @@ public class TestEraDisplayName {
};
}
@DataProvider
Object[][] allLocales() {
return Arrays.stream(Locale.getAvailableLocales())
.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);
}
@Test(dataProvider="allLocales")
public void test_reiwaNames(Locale locale) throws DateTimeParseException {
DateTimeFormatter f = JAPANESE_FORMATTER.withLocale(locale);
assertEquals(LocalDate.parse(REIWA_1ST.format(f), f), REIWA_1ST);
}
}