Skip to content

Commit

Permalink
8278434: timeouts in test java/time/test/java/time/format/TestZoneTex…
Browse files Browse the repository at this point in the history
…tPrinterParser.java

Backport-of: 8dc4437d002db5d025b47f48e7420e3bae55bdec
  • Loading branch information
GoeLin committed Mar 31, 2023
1 parent 1253eb4 commit 0f72c30
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2022, 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
Expand Down Expand Up @@ -151,8 +151,8 @@ private void deriveFallbackName(String[] names, int index, Locale locale, boolea

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

// Region Fallback
if (regionFormatFallback(names, index, locale)) {
return;
}

// Type Fallback
if (noDST && typeFallback(names, index)) {
return;
Expand All @@ -185,6 +180,11 @@ private void deriveFallbackName(String[] names, int index, Locale locale, boolea
}
}

// Region Fallback
if (regionFormatFallback(names, index, locale)) {
return;
}

// last resort
names[index] = toGMTFormat(id,
index == INDEX_DST_LONG || index == INDEX_DST_SHORT,
Expand Down Expand Up @@ -230,6 +230,11 @@ private boolean typeFallback(String[] names, int index) {
}

private boolean regionFormatFallback(String[] names, int index, Locale l) {
if (index % 2 == 0) {
// ignore short names
return false;
}

String id = names[INDEX_TZID];
LocaleResources lr = LocaleProviderAdapter.forType(Type.CLDR).getLocaleResources(l);
ResourceBundle fd = lr.getJavaTimeFormatData();
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2022, 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
Expand Down Expand Up @@ -49,7 +49,7 @@

/*
* @test
* @bug 8081022 8151876 8166875 8189784 8206980
* @bug 8081022 8151876 8166875 8189784 8206980 8278434
* @key randomness
*/

Expand All @@ -59,6 +59,11 @@
@Test
public class TestZoneTextPrinterParser extends AbstractTestPrinterParser {

private static final Locale[] SAMPLE_LOCALES = {
Locale.US, Locale.UK, Locale.FRANCE, Locale.GERMANY, Locale.ITALY, Locale.forLanguageTag("es"),
Locale.forLanguageTag("pt-BR"), Locale.forLanguageTag("ru"),
Locale.CHINA, Locale.TAIWAN, Locale.JAPAN, Locale.KOREA, Locale.ROOT};

protected static DateTimeFormatter getFormatter(Locale locale, TextStyle style) {
return new DateTimeFormatterBuilder().appendZoneText(style)
.toFormatter(locale)
Expand All @@ -68,7 +73,6 @@ protected static DateTimeFormatter getFormatter(Locale locale, TextStyle style)
public void test_printText() {
Random r = RandomFactory.getRandom();
int N = 8;
Locale[] locales = Locale.getAvailableLocales();
Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
ZonedDateTime zdt = ZonedDateTime.now();

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

public void test_ParseText() {
Locale[] locales = new Locale[] { Locale.ENGLISH, Locale.JAPANESE, Locale.FRENCH };
Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
for (Locale locale : locales) {
for (Locale locale : SAMPLE_LOCALES) {
parseText(zids, locale, TextStyle.FULL, false);
parseText(zids, locale, TextStyle.FULL, true);
parseText(zids, locale, TextStyle.SHORT, false);
Expand Down

1 comment on commit 0f72c30

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.