diff --git a/src/java.base/share/classes/java/text/BreakIterator.java b/src/java.base/share/classes/java/text/BreakIterator.java index e18039ca4f2..04849eed3d5 100644 --- a/src/java.base/share/classes/java/text/BreakIterator.java +++ b/src/java.base/share/classes/java/text/BreakIterator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2021, 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 @@ -576,8 +576,9 @@ public abstract class BreakIterator implements Cloneable * The returned array represents the union of locales supported by the Java * runtime and by installed * {@link java.text.spi.BreakIteratorProvider BreakIteratorProvider} implementations. - * It must contain at least a {@code Locale} - * instance equal to {@link java.util.Locale#US Locale.US}. + * At a minimum, the returned array must contain a {@code Locale} instance equal to + * {@link Locale#ROOT Locale.ROOT} and a {@code Locale} instance equal to + * {@link Locale#US Locale.US}. * * @return An array of locales for which localized * {@code BreakIterator} instances are available. diff --git a/src/java.base/share/classes/java/text/Collator.java b/src/java.base/share/classes/java/text/Collator.java index cc0ad518045..f011dbdccf3 100644 --- a/src/java.base/share/classes/java/text/Collator.java +++ b/src/java.base/share/classes/java/text/Collator.java @@ -421,8 +421,9 @@ public abstract class Collator * The returned array represents the union of locales supported * by the Java runtime and by installed * {@link java.text.spi.CollatorProvider CollatorProvider} implementations. - * It must contain at least a Locale instance equal to - * {@link java.util.Locale#US Locale.US}. + * At a minimum, the returned array must contain a {@code Locale} instance equal to + * {@link Locale#ROOT Locale.ROOT} and a {@code Locale} instance equal to + * {@link Locale#US Locale.US}. * * @return An array of locales for which localized * {@code Collator} instances are available. diff --git a/src/java.base/share/classes/java/text/DateFormat.java b/src/java.base/share/classes/java/text/DateFormat.java index bf40a911cd4..2750e266729 100644 --- a/src/java.base/share/classes/java/text/DateFormat.java +++ b/src/java.base/share/classes/java/text/DateFormat.java @@ -636,8 +636,9 @@ public abstract class DateFormat extends Format { * The returned array represents the union of locales supported by the Java * runtime and by installed * {@link java.text.spi.DateFormatProvider DateFormatProvider} implementations. - * It must contain at least a {@code Locale} instance equal to - * {@link java.util.Locale#US Locale.US}. + * At a minimum, the returned array must contain a {@code Locale} instance equal to + * {@link Locale#ROOT Locale.ROOT} and a {@code Locale} instance equal to + * {@link Locale#US Locale.US}. * * @return An array of locales for which localized * {@code DateFormat} instances are available. diff --git a/src/java.base/share/classes/java/text/DateFormatSymbols.java b/src/java.base/share/classes/java/text/DateFormatSymbols.java index e7919e33e69..a76c7cb44f4 100644 --- a/src/java.base/share/classes/java/text/DateFormatSymbols.java +++ b/src/java.base/share/classes/java/text/DateFormatSymbols.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2021, 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 @@ -299,8 +299,9 @@ public class DateFormatSymbols implements Serializable, Cloneable { * The returned array represents the union of locales supported by the * Java runtime and by installed * {@link java.text.spi.DateFormatSymbolsProvider DateFormatSymbolsProvider} - * implementations. It must contain at least a {@code Locale} - * instance equal to {@link java.util.Locale#US Locale.US}. + * implementations. At a minimum, the returned array must contain a + * {@code Locale} instance equal to {@link Locale#ROOT Locale.ROOT} and + * a {@code Locale} instance equal to {@link Locale#US Locale.US}. * * @return An array of locales for which localized * {@code DateFormatSymbols} instances are available. diff --git a/src/java.base/share/classes/java/text/DecimalFormatSymbols.java b/src/java.base/share/classes/java/text/DecimalFormatSymbols.java index 6741fd52667..11fd24573ef 100644 --- a/src/java.base/share/classes/java/text/DecimalFormatSymbols.java +++ b/src/java.base/share/classes/java/text/DecimalFormatSymbols.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2021, 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 @@ -122,8 +122,9 @@ public class DecimalFormatSymbols implements Cloneable, Serializable { * The returned array represents the union of locales supported by the Java * runtime and by installed * {@link java.text.spi.DecimalFormatSymbolsProvider DecimalFormatSymbolsProvider} - * implementations. It must contain at least a {@code Locale} - * instance equal to {@link java.util.Locale#US Locale.US}. + * implementations. At a minimum, the returned array must contain a + * {@code Locale} instance equal to {@link Locale#ROOT Locale.ROOT} and + * a {@code Locale} instance equal to {@link Locale#US Locale.US}. * * @return an array of locales for which localized * {@code DecimalFormatSymbols} instances are available. diff --git a/src/java.base/share/classes/java/text/NumberFormat.java b/src/java.base/share/classes/java/text/NumberFormat.java index f7c40284611..18c078f1a4e 100644 --- a/src/java.base/share/classes/java/text/NumberFormat.java +++ b/src/java.base/share/classes/java/text/NumberFormat.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2021, 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 @@ -682,8 +682,9 @@ public abstract class NumberFormat extends Format { * The returned array represents the union of locales supported by the Java * runtime and by installed * {@link java.text.spi.NumberFormatProvider NumberFormatProvider} implementations. - * It must contain at least a {@code Locale} instance equal to - * {@link java.util.Locale#US Locale.US}. + * At a minimum, the returned array must contain a {@code Locale} instance equal to + * {@link Locale#ROOT Locale.ROOT} and a {@code Locale} instance equal to + * {@link Locale#US Locale.US}. * * @return An array of locales for which localized * {@code NumberFormat} instances are available. diff --git a/src/java.base/share/classes/java/time/format/DecimalStyle.java b/src/java.base/share/classes/java/time/format/DecimalStyle.java index 590904fb66e..384da33243b 100644 --- a/src/java.base/share/classes/java/time/format/DecimalStyle.java +++ b/src/java.base/share/classes/java/time/format/DecimalStyle.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, 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 @@ -115,7 +115,9 @@ public final class DecimalStyle { /** * Lists all the locales that are supported. *

- * The locale 'en_US' will always be present. + * At a minimum, the returned {@code Set} must contain a {@code Locale} instance equal to + * {@link Locale#ROOT Locale.ROOT} and a {@code Locale} instance equal to + * {@link Locale#US Locale.US}. * * @return a Set of Locales for which localization is supported */ diff --git a/src/java.base/share/classes/java/util/Calendar.java b/src/java.base/share/classes/java/util/Calendar.java index 140634ec419..08954ac0104 100644 --- a/src/java.base/share/classes/java/util/Calendar.java +++ b/src/java.base/share/classes/java/util/Calendar.java @@ -1730,8 +1730,9 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable REQUIRED_LOCALES = Set.of(Locale.ROOT, Locale.US); + private static final MethodType ARRAY_RETURN_TYPE = MethodType.methodType(Locale.class.arrayType()); + private static final MethodType SET_RETURN_TYPE = MethodType.methodType(Set.class); + + @DataProvider + public Object[][] availableLocalesClasses() { + return new Object[][] { + {BreakIterator.class, ARRAY_RETURN_TYPE}, + {Calendar.class, ARRAY_RETURN_TYPE}, + {Collator.class, ARRAY_RETURN_TYPE}, + {DateFormat.class, ARRAY_RETURN_TYPE}, + {DateFormatSymbols.class, ARRAY_RETURN_TYPE}, + {DecimalFormatSymbols.class, ARRAY_RETURN_TYPE}, + {DecimalStyle.class, SET_RETURN_TYPE}, + {Locale.class, ARRAY_RETURN_TYPE}, + {NumberFormat.class, ARRAY_RETURN_TYPE}, + }; + } + + @Test (dataProvider = "availableLocalesClasses") + public void checkRequiredLocales(Class c, MethodType mt) throws Throwable { + var ret = MethodHandles.lookup().findStatic(c, "getAvailableLocales", mt).invoke(); + + if (ret instanceof Locale[] a) { + assertTrue(Arrays.asList(a).containsAll(REQUIRED_LOCALES)); + } else if (ret instanceof Set s) { + assertTrue(s.containsAll(REQUIRED_LOCALES)); + } else { + throw new RuntimeException("return type mismatch"); + } + } +}