Skip to content

Commit 0f72c30

Browse files
committed
8278434: timeouts in test java/time/test/java/time/format/TestZoneTextPrinterParser.java
Backport-of: 8dc4437d002db5d025b47f48e7420e3bae55bdec
1 parent 1253eb4 commit 0f72c30

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

src/java.base/share/classes/sun/util/cldr/CLDRTimeZoneNameProviderImpl.java

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -151,8 +151,8 @@ private void deriveFallbackName(String[] names, int index, Locale locale, boolea
151151

152152
// Check parent locales first
153153
if (!exists(names, index)) {
154-
CLDRLocaleProviderAdapter clpa = (CLDRLocaleProviderAdapter)LocaleProviderAdapter.forType(Type.CLDR);
155-
var cands = clpa.getCandidateLocales("", locale);
154+
var cands = ((CLDRLocaleProviderAdapter)LocaleProviderAdapter.forType(Type.CLDR))
155+
.getCandidateLocales("", locale);
156156
for (int i = 1; i < cands.size() ; i++) {
157157
String[] parentNames = super.getDisplayNameArray(id, cands.get(i));
158158
if (parentNames != null && !parentNames[index].isEmpty()) {
@@ -162,11 +162,6 @@ private void deriveFallbackName(String[] names, int index, Locale locale, boolea
162162
}
163163
}
164164

165-
// Region Fallback
166-
if (regionFormatFallback(names, index, locale)) {
167-
return;
168-
}
169-
170165
// Type Fallback
171166
if (noDST && typeFallback(names, index)) {
172167
return;
@@ -185,6 +180,11 @@ private void deriveFallbackName(String[] names, int index, Locale locale, boolea
185180
}
186181
}
187182

183+
// Region Fallback
184+
if (regionFormatFallback(names, index, locale)) {
185+
return;
186+
}
187+
188188
// last resort
189189
names[index] = toGMTFormat(id,
190190
index == INDEX_DST_LONG || index == INDEX_DST_SHORT,
@@ -230,6 +230,11 @@ private boolean typeFallback(String[] names, int index) {
230230
}
231231

232232
private boolean regionFormatFallback(String[] names, int index, Locale l) {
233+
if (index % 2 == 0) {
234+
// ignore short names
235+
return false;
236+
}
237+
233238
String id = names[INDEX_TZID];
234239
LocaleResources lr = LocaleProviderAdapter.forType(Type.CLDR).getLocaleResources(l);
235240
ResourceBundle fd = lr.getJavaTimeFormatData();

test/jdk/java/time/test/java/time/format/TestZoneTextPrinterParser.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -49,7 +49,7 @@
4949

5050
/*
5151
* @test
52-
* @bug 8081022 8151876 8166875 8189784 8206980
52+
* @bug 8081022 8151876 8166875 8189784 8206980 8278434
5353
* @key randomness
5454
*/
5555

@@ -59,6 +59,11 @@
5959
@Test
6060
public class TestZoneTextPrinterParser extends AbstractTestPrinterParser {
6161

62+
private static final Locale[] SAMPLE_LOCALES = {
63+
Locale.US, Locale.UK, Locale.FRANCE, Locale.GERMANY, Locale.ITALY, Locale.forLanguageTag("es"),
64+
Locale.forLanguageTag("pt-BR"), Locale.forLanguageTag("ru"),
65+
Locale.CHINA, Locale.TAIWAN, Locale.JAPAN, Locale.KOREA, Locale.ROOT};
66+
6267
protected static DateTimeFormatter getFormatter(Locale locale, TextStyle style) {
6368
return new DateTimeFormatterBuilder().appendZoneText(style)
6469
.toFormatter(locale)
@@ -68,7 +73,6 @@ protected static DateTimeFormatter getFormatter(Locale locale, TextStyle style)
6873
public void test_printText() {
6974
Random r = RandomFactory.getRandom();
7075
int N = 8;
71-
Locale[] locales = Locale.getAvailableLocales();
7276
Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
7377
ZonedDateTime zdt = ZonedDateTime.now();
7478

@@ -83,7 +87,7 @@ public void test_printText() {
8387
zdt = zdt.withZoneSameLocal(ZoneId.of(zid));
8488
TimeZone tz = TimeZone.getTimeZone(zid);
8589
boolean isDST = tz.inDaylightTime(new Date(zdt.toInstant().toEpochMilli()));
86-
for (Locale locale : locales) {
90+
for (Locale locale : SAMPLE_LOCALES) {
8791
String longDisplayName = tz.getDisplayName(isDST, TimeZone.LONG, locale);
8892
String shortDisplayName = tz.getDisplayName(isDST, TimeZone.SHORT, locale);
8993
if ((longDisplayName.startsWith("GMT+") && shortDisplayName.startsWith("GMT+"))
@@ -116,9 +120,8 @@ private void printText(Locale locale, ZonedDateTime zdt, TextStyle style, TimeZo
116120
}
117121

118122
public void test_ParseText() {
119-
Locale[] locales = new Locale[] { Locale.ENGLISH, Locale.JAPANESE, Locale.FRENCH };
120123
Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
121-
for (Locale locale : locales) {
124+
for (Locale locale : SAMPLE_LOCALES) {
122125
parseText(zids, locale, TextStyle.FULL, false);
123126
parseText(zids, locale, TextStyle.FULL, true);
124127
parseText(zids, locale, TextStyle.SHORT, false);

0 commit comments

Comments
 (0)