Skip to content

Commit 0c409ca

Browse files
committed
8276186: Require getAvailableLocales() methods to include Locale.ROOT
Reviewed-by: prappo, smarks, iris
1 parent df02daa commit 0c409ca

File tree

10 files changed

+108
-22
lines changed

10 files changed

+108
-22
lines changed

src/java.base/share/classes/java/text/BreakIterator.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2021, 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
@@ -576,8 +576,9 @@ private static BreakIterator createBreakInstance(LocaleProviderAdapter adapter,
576576
* The returned array represents the union of locales supported by the Java
577577
* runtime and by installed
578578
* {@link java.text.spi.BreakIteratorProvider BreakIteratorProvider} implementations.
579-
* It must contain at least a {@code Locale}
580-
* instance equal to {@link java.util.Locale#US Locale.US}.
579+
* At a minimum, the returned array must contain a {@code Locale} instance equal to
580+
* {@link Locale#ROOT Locale.ROOT} and a {@code Locale} instance equal to
581+
* {@link Locale#US Locale.US}.
581582
*
582583
* @return An array of locales for which localized
583584
* {@code BreakIterator} instances are available.

src/java.base/share/classes/java/text/Collator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,9 @@ public synchronized void setDecomposition(int decompositionMode) {
421421
* The returned array represents the union of locales supported
422422
* by the Java runtime and by installed
423423
* {@link java.text.spi.CollatorProvider CollatorProvider} implementations.
424-
* It must contain at least a Locale instance equal to
425-
* {@link java.util.Locale#US Locale.US}.
424+
* At a minimum, the returned array must contain a {@code Locale} instance equal to
425+
* {@link Locale#ROOT Locale.ROOT} and a {@code Locale} instance equal to
426+
* {@link Locale#US Locale.US}.
426427
*
427428
* @return An array of locales for which localized
428429
* {@code Collator} instances are available.

src/java.base/share/classes/java/text/DateFormat.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,9 @@ public static final DateFormat getInstance() {
636636
* The returned array represents the union of locales supported by the Java
637637
* runtime and by installed
638638
* {@link java.text.spi.DateFormatProvider DateFormatProvider} implementations.
639-
* It must contain at least a {@code Locale} instance equal to
640-
* {@link java.util.Locale#US Locale.US}.
639+
* At a minimum, the returned array must contain a {@code Locale} instance equal to
640+
* {@link Locale#ROOT Locale.ROOT} and a {@code Locale} instance equal to
641+
* {@link Locale#US Locale.US}.
641642
*
642643
* @return An array of locales for which localized
643644
* {@code DateFormat} instances are available.

src/java.base/share/classes/java/text/DateFormatSymbols.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2021, 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
@@ -299,8 +299,9 @@ private DateFormatSymbols(boolean flag) {
299299
* The returned array represents the union of locales supported by the
300300
* Java runtime and by installed
301301
* {@link java.text.spi.DateFormatSymbolsProvider DateFormatSymbolsProvider}
302-
* implementations. It must contain at least a {@code Locale}
303-
* instance equal to {@link java.util.Locale#US Locale.US}.
302+
* implementations. At a minimum, the returned array must contain a
303+
* {@code Locale} instance equal to {@link Locale#ROOT Locale.ROOT} and
304+
* a {@code Locale} instance equal to {@link Locale#US Locale.US}.
304305
*
305306
* @return An array of locales for which localized
306307
* {@code DateFormatSymbols} instances are available.

src/java.base/share/classes/java/text/DecimalFormatSymbols.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2021, 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
@@ -122,8 +122,9 @@ public DecimalFormatSymbols( Locale locale ) {
122122
* The returned array represents the union of locales supported by the Java
123123
* runtime and by installed
124124
* {@link java.text.spi.DecimalFormatSymbolsProvider DecimalFormatSymbolsProvider}
125-
* implementations. It must contain at least a {@code Locale}
126-
* instance equal to {@link java.util.Locale#US Locale.US}.
125+
* implementations. At a minimum, the returned array must contain a
126+
* {@code Locale} instance equal to {@link Locale#ROOT Locale.ROOT} and
127+
* a {@code Locale} instance equal to {@link Locale#US Locale.US}.
127128
*
128129
* @return an array of locales for which localized
129130
* {@code DecimalFormatSymbols} instances are available.

src/java.base/share/classes/java/text/NumberFormat.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2021, 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
@@ -682,8 +682,9 @@ public static NumberFormat getCompactNumberInstance(Locale locale,
682682
* The returned array represents the union of locales supported by the Java
683683
* runtime and by installed
684684
* {@link java.text.spi.NumberFormatProvider NumberFormatProvider} implementations.
685-
* It must contain at least a {@code Locale} instance equal to
686-
* {@link java.util.Locale#US Locale.US}.
685+
* At a minimum, the returned array must contain a {@code Locale} instance equal to
686+
* {@link Locale#ROOT Locale.ROOT} and a {@code Locale} instance equal to
687+
* {@link Locale#US Locale.US}.
687688
*
688689
* @return An array of locales for which localized
689690
* {@code NumberFormat} instances are available.

src/java.base/share/classes/java/time/format/DecimalStyle.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2021, 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
@@ -115,7 +115,9 @@ public final class DecimalStyle {
115115
/**
116116
* Lists all the locales that are supported.
117117
* <p>
118-
* The locale 'en_US' will always be present.
118+
* At a minimum, the returned {@code Set} must contain a {@code Locale} instance equal to
119+
* {@link Locale#ROOT Locale.ROOT} and a {@code Locale} instance equal to
120+
* {@link Locale#US Locale.US}.
119121
*
120122
* @return a Set of Locales for which localization is supported
121123
*/

src/java.base/share/classes/java/util/Calendar.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,8 +1730,9 @@ private static Calendar createCalendar(TimeZone zone,
17301730
/**
17311731
* Returns an array of all locales for which the {@code getInstance}
17321732
* methods of this class can return localized instances.
1733-
* The array returned must contain at least a {@code Locale}
1734-
* instance equal to {@link java.util.Locale#US Locale.US}.
1733+
* At a minimum, the returned array must contain a {@code Locale} instance equal to
1734+
* {@link Locale#ROOT Locale.ROOT} and a {@code Locale} instance equal to
1735+
* {@link Locale#US Locale.US}.
17351736
*
17361737
* @return An array of locales for which localized
17371738
* {@code Calendar} instances are available.

src/java.base/share/classes/java/util/Locale.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,8 +1126,9 @@ public static synchronized void setDefault(Locale.Category category,
11261126
* The returned array represents the union of locales supported
11271127
* by the Java runtime environment and by installed
11281128
* {@link java.util.spi.LocaleServiceProvider LocaleServiceProvider}
1129-
* implementations. It must contain at least a {@code Locale}
1130-
* instance equal to {@link java.util.Locale#US Locale.US}.
1129+
* implementations. At a minimum, the returned array must contain a
1130+
* {@code Locale} instance equal to {@link Locale#ROOT Locale.ROOT} and
1131+
* a {@code Locale} instance equal to {@link Locale#US Locale.US}.
11311132
*
11321133
* @return An array of installed locales.
11331134
*/
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
/**
24+
* @test
25+
* @bug 8276186
26+
* @summary Checks whether getAvailableLocales() returns at least Locale.ROOT and
27+
* Locale.US instances.
28+
* @run testng/othervm -Djava.locale.providers=COMPAT RequiredAvailableLocalesTest
29+
* @run testng/othervm -Djava.locale.providers=CLDR RequiredAvailableLocalesTest
30+
*/
31+
32+
import java.lang.invoke.MethodHandles;
33+
import java.lang.invoke.MethodType;
34+
import java.text.*;
35+
import java.time.format.DecimalStyle;
36+
import java.util.*;
37+
38+
import org.testng.annotations.DataProvider;
39+
import org.testng.annotations.Test;
40+
import static org.testng.Assert.assertTrue;
41+
42+
@Test
43+
public class RequiredAvailableLocalesTest {
44+
45+
private static final Set<Locale> REQUIRED_LOCALES = Set.of(Locale.ROOT, Locale.US);
46+
private static final MethodType ARRAY_RETURN_TYPE = MethodType.methodType(Locale.class.arrayType());
47+
private static final MethodType SET_RETURN_TYPE = MethodType.methodType(Set.class);
48+
49+
@DataProvider
50+
public Object[][] availableLocalesClasses() {
51+
return new Object[][] {
52+
{BreakIterator.class, ARRAY_RETURN_TYPE},
53+
{Calendar.class, ARRAY_RETURN_TYPE},
54+
{Collator.class, ARRAY_RETURN_TYPE},
55+
{DateFormat.class, ARRAY_RETURN_TYPE},
56+
{DateFormatSymbols.class, ARRAY_RETURN_TYPE},
57+
{DecimalFormatSymbols.class, ARRAY_RETURN_TYPE},
58+
{DecimalStyle.class, SET_RETURN_TYPE},
59+
{Locale.class, ARRAY_RETURN_TYPE},
60+
{NumberFormat.class, ARRAY_RETURN_TYPE},
61+
};
62+
}
63+
64+
@Test (dataProvider = "availableLocalesClasses")
65+
public void checkRequiredLocales(Class<?> c, MethodType mt) throws Throwable {
66+
var ret = MethodHandles.lookup().findStatic(c, "getAvailableLocales", mt).invoke();
67+
68+
if (ret instanceof Locale[] a) {
69+
assertTrue(Arrays.asList(a).containsAll(REQUIRED_LOCALES));
70+
} else if (ret instanceof Set<?> s) {
71+
assertTrue(s.containsAll(REQUIRED_LOCALES));
72+
} else {
73+
throw new RuntimeException("return type mismatch");
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)