src/share/classes/sun/util/locale/provider/LocaleServiceProviderPool.java
Print this page
rev 6057 : imported patch 8001205.8001562
@@ -24,10 +24,11 @@
*/
package sun.util.locale.provider;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.IllformedLocaleException;
import java.util.List;
import java.util.Locale;
@@ -175,11 +176,11 @@
static {
Set<Locale> all = new HashSet<>();
for (Class<? extends LocaleServiceProvider> c : spiClasses) {
LocaleServiceProviderPool pool =
LocaleServiceProviderPool.getPool(c);
- all.addAll(pool.getAvailableLocaleList());
+ all.addAll(pool.getAvailableLocaleSet());
}
allAvailableLocales = all.toArray(new Locale[0]);
}
@@ -200,33 +201,40 @@
}
/**
* Returns an array of available locales. This array is a
* merged array of all the locales that are provided by each
- * provider, including the JRE.
+ * provider, including the JRE's FormatData locales.
*
* @return an array of the available locales
*/
public Locale[] getAvailableLocales() {
- Set<Locale> locList = getAvailableLocaleList();
+ Set<Locale> locList = new HashSet<>();
+ locList.addAll(getAvailableLocaleSet());
+ // Make sure it all contains JRE's FormatData locales for compatibility.
+ locList.addAll(Arrays.asList(LocaleProviderAdapter.forJRE().getAvailableLocales()));
Locale[] tmp = new Locale[locList.size()];
locList.toArray(tmp);
return tmp;
}
- private synchronized Set<Locale> getAvailableLocaleList() {
+ /**
+ * Returns the union of locale sets that are available from
+ * each service provider. This method does NOT return the
+ * defensive copy.
+ *
+ * @return a set of available locales
+ */
+ private synchronized Set<Locale> getAvailableLocaleSet() {
if (availableLocales == null) {
availableLocales = new HashSet<>();
for (LocaleServiceProvider lsp : providers.values()) {
Locale[] locales = lsp.getAvailableLocales();
for (Locale locale: locales) {
availableLocales.add(getLookupLocale(locale));
}
}
-
- // Remove Locale.ROOT for the compatibility.
- availableLocales.remove(Locale.ROOT);
}
return availableLocales;
}
@@ -293,11 +301,11 @@
locale, key, params);
}
List<Locale> lookupLocales = getLookupLocales(locale);
- Set<Locale> available = getAvailableLocaleList();
+ Set<Locale> available = getAvailableLocaleSet();
for (Locale current : lookupLocales) {
if (available.contains(current)) {
S providersObj;
for (LocaleProviderAdapter.Type type: findProviders(current)) {