8224105: Cannot parse JapaneseDate string on some specified locales
Reviewed-by: bchristi
--- a/src/java.base/share/classes/sun/util/locale/provider/CalendarNameProviderImpl.java Tue May 21 15:59:46 2019 -0400
+++ b/src/java.base/share/classes/sun/util/locale/provider/CalendarNameProviderImpl.java Tue May 21 13:40:56 2019 -0700
@@ -257,11 +257,13 @@
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;
--- a/test/jdk/java/time/test/java/time/chrono/TestEraDisplayName.java Tue May 21 15:59:46 2019 -0400
+++ b/test/jdk/java/time/test/java/time/chrono/TestEraDisplayName.java Tue May 21 13:40:56 2019 -0700
@@ -28,7 +28,9 @@
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 @@
* 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 @@
};
}
+ @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);
+ }
}