提交 3199964b 编写于 作者: N naoto

7196799: CLDR adapter can not be invoked when region code is specified in Locale

7197573: java/util/Locale/LocaleProviders.sh failed.
Reviewed-by: okutsu
上级 2823a7f1
...@@ -213,6 +213,7 @@ JAVA_JAVA_java = \ ...@@ -213,6 +213,7 @@ JAVA_JAVA_java = \
sun/util/locale/provider/DateFormatSymbolsProviderImpl.java \ sun/util/locale/provider/DateFormatSymbolsProviderImpl.java \
sun/util/locale/provider/DecimalFormatSymbolsProviderImpl.java \ sun/util/locale/provider/DecimalFormatSymbolsProviderImpl.java \
sun/util/locale/provider/DictionaryBasedBreakIterator.java \ sun/util/locale/provider/DictionaryBasedBreakIterator.java \
sun/util/locale/provider/FallbackLocaleProviderAdapter.java \
sun/util/locale/provider/HostLocaleProviderAdapter.java \ sun/util/locale/provider/HostLocaleProviderAdapter.java \
sun/util/locale/provider/HostLocaleProviderAdapterImpl.java \ sun/util/locale/provider/HostLocaleProviderAdapterImpl.java \
sun/util/locale/provider/JRELocaleConstants.java \ sun/util/locale/provider/JRELocaleConstants.java \
......
...@@ -137,7 +137,7 @@ public class CalendarDataProviderImpl extends CalendarDataProvider implements Av ...@@ -137,7 +137,7 @@ public class CalendarDataProviderImpl extends CalendarDataProvider implements Av
@Override @Override
public boolean isSupportedLocale(Locale locale) { public boolean isSupportedLocale(Locale locale) {
if (locale == Locale.ROOT) { if (Locale.ROOT.equals(locale)) {
return true; return true;
} }
String calendarType = null; String calendarType = null;
......
/*
* Copyright (c) 2012, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.util.locale.provider;
/**
* FallbackProviderAdapter implementation.
*
* @author Naoto Sato
*/
public class FallbackLocaleProviderAdapter extends JRELocaleProviderAdapter {
/**
* Returns the type of this LocaleProviderAdapter
*/
@Override
public LocaleProviderAdapter.Type getAdapterType() {
return Type.FALLBACK;
}
}
...@@ -71,7 +71,7 @@ public class JRELocaleProviderAdapter extends LocaleProviderAdapter { ...@@ -71,7 +71,7 @@ public class JRELocaleProviderAdapter extends LocaleProviderAdapter {
*/ */
@Override @Override
public LocaleProviderAdapter.Type getAdapterType() { public LocaleProviderAdapter.Type getAdapterType() {
return LocaleProviderAdapter.Type.JRE; return Type.JRE;
} }
/** /**
......
...@@ -59,7 +59,8 @@ public abstract class LocaleProviderAdapter { ...@@ -59,7 +59,8 @@ public abstract class LocaleProviderAdapter {
JRE("sun.util.resources", "sun.text.resources"), JRE("sun.util.resources", "sun.text.resources"),
CLDR("sun.util.resources.cldr", "sun.text.resources.cldr"), CLDR("sun.util.resources.cldr", "sun.text.resources.cldr"),
SPI, SPI,
HOST; HOST,
FALLBACK("sun.util.resources", "sun.text.resources");
private final String UTIL_RESOURCES_PACKAGE; private final String UTIL_RESOURCES_PACKAGE;
private final String TEXT_RESOURCES_PACKAGE; private final String TEXT_RESOURCES_PACKAGE;
...@@ -111,6 +112,12 @@ public abstract class LocaleProviderAdapter { ...@@ -111,6 +112,12 @@ public abstract class LocaleProviderAdapter {
*/ */
private static LocaleProviderAdapter hostLocaleProviderAdapter = null; private static LocaleProviderAdapter hostLocaleProviderAdapter = null;
/**
* FALLBACK Locale Data Adapter instance. It's basically the same with JRE, but only kicks
* in for the root locale.
*/
private static LocaleProviderAdapter fallbackLocaleProviderAdapter = null;
static { static {
String order = AccessController.doPrivileged( String order = AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("java.locale.providers")); new sun.security.action.GetPropertyAction("java.locale.providers"));
...@@ -132,21 +139,23 @@ public abstract class LocaleProviderAdapter { ...@@ -132,21 +139,23 @@ public abstract class LocaleProviderAdapter {
break; break;
} }
typeList.add(aType); typeList.add(aType);
} catch (// could be caused by the user specifying wrong } catch (IllegalArgumentException | UnsupportedOperationException e) {
// could be caused by the user specifying wrong
// provider name or format in the system property // provider name or format in the system property
IllegalArgumentException |
UnsupportedOperationException e) {
LocaleServiceProviderPool.config(LocaleProviderAdapter.class, e.toString()); LocaleServiceProviderPool.config(LocaleProviderAdapter.class, e.toString());
} }
} }
if (!typeList.isEmpty()) {
if (!typeList.contains(Type.JRE)) { if (!typeList.contains(Type.JRE)) {
// Append JRE as the last resort. // Append FALLBACK as the last resort.
typeList.add(Type.JRE); fallbackLocaleProviderAdapter = new FallbackLocaleProviderAdapter();
typeList.add(Type.FALLBACK);
} }
adapterPreference = typeList.toArray(new Type[0]); adapterPreference = typeList.toArray(new Type[0]);
} }
} }
}
/** /**
...@@ -162,6 +171,8 @@ public abstract class LocaleProviderAdapter { ...@@ -162,6 +171,8 @@ public abstract class LocaleProviderAdapter {
return spiLocaleProviderAdapter; return spiLocaleProviderAdapter;
case HOST: case HOST:
return hostLocaleProviderAdapter; return hostLocaleProviderAdapter;
case FALLBACK:
return fallbackLocaleProviderAdapter;
default: default:
throw new InternalError("unknown locale data adapter type"); throw new InternalError("unknown locale data adapter type");
} }
...@@ -173,7 +184,7 @@ public abstract class LocaleProviderAdapter { ...@@ -173,7 +184,7 @@ public abstract class LocaleProviderAdapter {
public static LocaleProviderAdapter getResourceBundleBased() { public static LocaleProviderAdapter getResourceBundleBased() {
for (Type type : getAdapterPreference()) { for (Type type : getAdapterPreference()) {
if (type == Type.JRE || type == Type.CLDR) { if (type == Type.JRE || type == Type.CLDR || type == Type.FALLBACK) {
return forType(type); return forType(type);
} }
} }
...@@ -218,8 +229,8 @@ public abstract class LocaleProviderAdapter { ...@@ -218,8 +229,8 @@ public abstract class LocaleProviderAdapter {
} }
} }
// returns the adapter for JRE as the last resort // returns the adapter for FALLBACK as the last resort
return jreLocaleProviderAdapter; return fallbackLocaleProviderAdapter;
} }
private static LocaleProviderAdapter findAdapter(Class<? extends LocaleServiceProvider> providerClass, private static LocaleProviderAdapter findAdapter(Class<? extends LocaleServiceProvider> providerClass,
...@@ -238,18 +249,24 @@ public abstract class LocaleProviderAdapter { ...@@ -238,18 +249,24 @@ public abstract class LocaleProviderAdapter {
/** /**
* A utility method for implementing the default LocaleServiceProvider.isSupportedLocale * A utility method for implementing the default LocaleServiceProvider.isSupportedLocale
* for the JRE and CLDR adapters. * for the JRE, CLDR, and FALLBACK adapters.
*/ */
static boolean isSupportedLocale(Locale locale, LocaleProviderAdapter.Type type, Set<String> langtags) { static boolean isSupportedLocale(Locale locale, LocaleProviderAdapter.Type type, Set<String> langtags) {
assert type == Type.JRE || type == Type.CLDR; assert type == Type.JRE || type == Type.CLDR || type == Type.FALLBACK;
if (locale == Locale.ROOT) { if (Locale.ROOT.equals(locale)) {
return true; return true;
} }
if (type == Type.FALLBACK) {
// no other locales except ROOT are supported for FALLBACK
return false;
}
locale = locale.stripExtensions(); locale = locale.stripExtensions();
if (langtags.contains(locale.toLanguageTag())) { if (langtags.contains(locale.toLanguageTag())) {
return true; return true;
} }
if (type == LocaleProviderAdapter.Type.JRE) { if (type == Type.JRE) {
String oldname = locale.toString().replace('_', '-'); String oldname = locale.toString().replace('_', '-');
return langtags.contains(oldname); return langtags.contains(oldname);
} }
......
...@@ -27,8 +27,13 @@ import sun.util.locale.provider.LocaleProviderAdapter; ...@@ -27,8 +27,13 @@ import sun.util.locale.provider.LocaleProviderAdapter;
public class LocaleProviders { public class LocaleProviders {
public static void main(String[] args) { public static void main(String[] args) {
if (args.length == 0) {
// no args indicates that the caller is asking the platform default locale.
Locale defloc = Locale.getDefault();
System.out.printf("%s,%s\n", defloc.getLanguage(), defloc.getCountry());
} else {
String expected = args[0]; String expected = args[0];
Locale testLocale = new Locale(args[1], args[2]); Locale testLocale = new Locale(args[1], (args.length >= 3 ? args[2] : ""));
String preference = System.getProperty("java.locale.providers", ""); String preference = System.getProperty("java.locale.providers", "");
LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, testLocale); LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, testLocale);
LocaleProviderAdapter.Type type = lda.getAdapterType(); LocaleProviderAdapter.Type type = lda.getAdapterType();
...@@ -37,4 +42,5 @@ public class LocaleProviders { ...@@ -37,4 +42,5 @@ public class LocaleProviders {
throw new RuntimeException("Returned locale data adapter is not correct."); throw new RuntimeException("Returned locale data adapter is not correct.");
} }
} }
}
} }
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#!/bin/sh #!/bin/sh
# #
# @test # @test
# @bug 6336885 # @bug 6336885 7196799 7197573
# @summary tests for "java.locale.providers" system property # @summary tests for "java.locale.providers" system property
# @compile -XDignore.symbol.file LocaleProviders.java # @compile -XDignore.symbol.file LocaleProviders.java
# @run shell/timeout=600 LocaleProviders.sh # @run shell/timeout=600 LocaleProviders.sh
...@@ -65,9 +65,16 @@ case "$OS" in ...@@ -65,9 +65,16 @@ case "$OS" in
;; ;;
esac esac
# get the platform default locale
PLATDEF=`${TESTJAVA}${FS}bin${FS}java -classpath ${TESTCLASSES} LocaleProviders`
DEFLANG=`echo ${PLATDEF} | sed -e "s/,.*//"`
DEFCTRY=`echo ${PLATDEF} | sed -e "s/.*,//"`
echo "DEFLANG=${DEFLANG}"
echo "DEFCTRY=${DEFCTRY}"
runTest() runTest()
{ {
RUNCMD="${TESTJAVA}${FS}bin${FS}java -classpath ${TESTCLASSES} -Duser.language=$DEFLANG -Duser.country=$DEFCTRY -Djava.locale.providers=$PREFLIST LocaleProviders $EXPECTED $TESTLANG $TESTCTRY" RUNCMD="${TESTJAVA}${FS}bin${FS}java -classpath ${TESTCLASSES} -Djava.locale.providers=$PREFLIST LocaleProviders $EXPECTED $TESTLANG $TESTCTRY"
echo ${RUNCMD} echo ${RUNCMD}
${RUNCMD} ${RUNCMD}
result=$? result=$?
...@@ -81,9 +88,7 @@ runTest() ...@@ -81,9 +88,7 @@ runTest()
} }
# testing HOST is selected for the default locale, if specified on Windows or MacOSX # testing HOST is selected for the default locale, if specified on Windows or MacOSX
DEFLANG=en PREFLIST=HOST,JRE
DEFCTRY=US
PREFLIST=HOST
case "$OS" in case "$OS" in
Windows_NT* ) Windows_NT* )
WINVER=`uname -r` WINVER=`uname -r`
...@@ -101,28 +106,32 @@ case "$OS" in ...@@ -101,28 +106,32 @@ case "$OS" in
EXPECTED=JRE EXPECTED=JRE
;; ;;
esac esac
TESTLANG=en TESTLANG=${DEFLANG}
TESTCTRY=US TESTCTRY=${DEFCTRY}
runTest runTest
# testing HOST is NOT selected for the non-default locale, if specified # testing HOST is NOT selected for the non-default locale, if specified
DEFLANG=en PREFLIST=HOST,JRE
DEFCTRY=US
PREFLIST=HOST
EXPECTED=JRE EXPECTED=JRE
TESTLANG=en if [ "${DEFLANG}" = "en" ]
TESTCTRY=GB then
TESTLANG=ja
TESTCTRY=JP
else
TESTLANG=en
TESTCTRY=US
fi
runTest runTest
# testing SPI is NOT selected, as there is none. # testing SPI is NOT selected, as there is none.
PREFLIST=SPI PREFLIST=SPI,JRE
EXPECTED=JRE EXPECTED=JRE
TESTLANG=en TESTLANG=en
TESTCTRY=US TESTCTRY=US
runTest runTest
# testing the order, variaton #1. This assumes en_GB DateFormat data are available both in JRE & CLDR # testing the order, variaton #1. This assumes en_GB DateFormat data are available both in JRE & CLDR
PREFLIST=CLDR PREFLIST=CLDR,JRE
EXPECTED=CLDR EXPECTED=CLDR
TESTLANG=en TESTLANG=en
TESTCTRY=GB TESTCTRY=GB
...@@ -142,4 +151,28 @@ TESTLANG=haw ...@@ -142,4 +151,28 @@ TESTLANG=haw
TESTCTRY=GB TESTCTRY=GB
runTest runTest
# testing the order, variaton #4 for the bug 7196799. CLDR's "zh" data should be used in "zh_CN"
PREFLIST=CLDR
EXPECTED=CLDR
TESTLANG=zh
TESTCTRY=CN
runTest
# testing FALLBACK provider. SPI and invalid one cases.
PREFLIST=SPI
EXPECTED=FALLBACK
TESTLANG=en
TESTCTRY=US
runTest
PREFLIST=FOO
EXPECTED=JRE
TESTLANG=en
TESTCTRY=US
runTest
PREFLIST=BAR,SPI
EXPECTED=FALLBACK
TESTLANG=en
TESTCTRY=US
runTest
exit $result exit $result
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册