7198834: HOST Adapter: one extra empty space in the end of the pattern string

Reviewed-by: okutsu
This commit is contained in:
Naoto Sato 2012-10-05 09:57:50 -07:00
parent 0dcbdaafba
commit eeac68872b
4 changed files with 137 additions and 80 deletions

View File

@ -125,7 +125,7 @@ public class JRELocaleProviderAdapter extends LocaleProviderAdapter {
public BreakIteratorProvider getBreakIteratorProvider() { public BreakIteratorProvider getBreakIteratorProvider() {
if (breakIteratorProvider == null) { if (breakIteratorProvider == null) {
BreakIteratorProvider provider = new BreakIteratorProviderImpl(getAdapterType(), BreakIteratorProvider provider = new BreakIteratorProviderImpl(getAdapterType(),
getLanguateTagSet("FormatData")); getLanguageTagSet("FormatData"));
synchronized (this) { synchronized (this) {
if (breakIteratorProvider == null) { if (breakIteratorProvider == null) {
breakIteratorProvider = provider; breakIteratorProvider = provider;
@ -139,7 +139,7 @@ public class JRELocaleProviderAdapter extends LocaleProviderAdapter {
public CollatorProvider getCollatorProvider() { public CollatorProvider getCollatorProvider() {
if (collatorProvider == null) { if (collatorProvider == null) {
CollatorProvider provider = new CollatorProviderImpl(getAdapterType(), CollatorProvider provider = new CollatorProviderImpl(getAdapterType(),
getLanguateTagSet("CollationData")); getLanguageTagSet("CollationData"));
synchronized (this) { synchronized (this) {
if (collatorProvider == null) { if (collatorProvider == null) {
collatorProvider = provider; collatorProvider = provider;
@ -153,7 +153,7 @@ public class JRELocaleProviderAdapter extends LocaleProviderAdapter {
public DateFormatProvider getDateFormatProvider() { public DateFormatProvider getDateFormatProvider() {
if (dateFormatProvider == null) { if (dateFormatProvider == null) {
DateFormatProvider provider = new DateFormatProviderImpl(getAdapterType(), DateFormatProvider provider = new DateFormatProviderImpl(getAdapterType(),
getLanguateTagSet("FormatData")); getLanguageTagSet("FormatData"));
synchronized (this) { synchronized (this) {
if (dateFormatProvider == null) { if (dateFormatProvider == null) {
dateFormatProvider = provider; dateFormatProvider = provider;
@ -167,7 +167,7 @@ public class JRELocaleProviderAdapter extends LocaleProviderAdapter {
public DateFormatSymbolsProvider getDateFormatSymbolsProvider() { public DateFormatSymbolsProvider getDateFormatSymbolsProvider() {
if (dateFormatSymbolsProvider == null) { if (dateFormatSymbolsProvider == null) {
DateFormatSymbolsProvider provider = new DateFormatSymbolsProviderImpl(getAdapterType(), DateFormatSymbolsProvider provider = new DateFormatSymbolsProviderImpl(getAdapterType(),
getLanguateTagSet("FormatData")); getLanguageTagSet("FormatData"));
synchronized (this) { synchronized (this) {
if (dateFormatSymbolsProvider == null) { if (dateFormatSymbolsProvider == null) {
dateFormatSymbolsProvider = provider; dateFormatSymbolsProvider = provider;
@ -180,7 +180,7 @@ public class JRELocaleProviderAdapter extends LocaleProviderAdapter {
@Override @Override
public DecimalFormatSymbolsProvider getDecimalFormatSymbolsProvider() { public DecimalFormatSymbolsProvider getDecimalFormatSymbolsProvider() {
if (decimalFormatSymbolsProvider == null) { if (decimalFormatSymbolsProvider == null) {
DecimalFormatSymbolsProvider provider = new DecimalFormatSymbolsProviderImpl(getAdapterType(), getLanguateTagSet("FormatData")); DecimalFormatSymbolsProvider provider = new DecimalFormatSymbolsProviderImpl(getAdapterType(), getLanguageTagSet("FormatData"));
synchronized (this) { synchronized (this) {
if (decimalFormatSymbolsProvider == null) { if (decimalFormatSymbolsProvider == null) {
decimalFormatSymbolsProvider = provider; decimalFormatSymbolsProvider = provider;
@ -194,7 +194,7 @@ public class JRELocaleProviderAdapter extends LocaleProviderAdapter {
public NumberFormatProvider getNumberFormatProvider() { public NumberFormatProvider getNumberFormatProvider() {
if (numberFormatProvider == null) { if (numberFormatProvider == null) {
NumberFormatProvider provider = new NumberFormatProviderImpl(getAdapterType(), NumberFormatProvider provider = new NumberFormatProviderImpl(getAdapterType(),
getLanguateTagSet("FormatData")); getLanguageTagSet("FormatData"));
synchronized (this) { synchronized (this) {
if (numberFormatProvider == null) { if (numberFormatProvider == null) {
numberFormatProvider = provider; numberFormatProvider = provider;
@ -211,7 +211,7 @@ public class JRELocaleProviderAdapter extends LocaleProviderAdapter {
public CurrencyNameProvider getCurrencyNameProvider() { public CurrencyNameProvider getCurrencyNameProvider() {
if (currencyNameProvider == null) { if (currencyNameProvider == null) {
CurrencyNameProvider provider = new CurrencyNameProviderImpl(getAdapterType(), CurrencyNameProvider provider = new CurrencyNameProviderImpl(getAdapterType(),
getLanguateTagSet("CurrencyNames")); getLanguageTagSet("CurrencyNames"));
synchronized (this) { synchronized (this) {
if (currencyNameProvider == null) { if (currencyNameProvider == null) {
currencyNameProvider = provider; currencyNameProvider = provider;
@ -225,7 +225,7 @@ public class JRELocaleProviderAdapter extends LocaleProviderAdapter {
public LocaleNameProvider getLocaleNameProvider() { public LocaleNameProvider getLocaleNameProvider() {
if (localeNameProvider == null) { if (localeNameProvider == null) {
LocaleNameProvider provider = new LocaleNameProviderImpl(getAdapterType(), LocaleNameProvider provider = new LocaleNameProviderImpl(getAdapterType(),
getLanguateTagSet("LocaleNames")); getLanguageTagSet("LocaleNames"));
synchronized (this) { synchronized (this) {
if (localeNameProvider == null) { if (localeNameProvider == null) {
localeNameProvider = provider; localeNameProvider = provider;
@ -239,7 +239,7 @@ public class JRELocaleProviderAdapter extends LocaleProviderAdapter {
public TimeZoneNameProvider getTimeZoneNameProvider() { public TimeZoneNameProvider getTimeZoneNameProvider() {
if (timeZoneNameProvider == null) { if (timeZoneNameProvider == null) {
TimeZoneNameProvider provider = new TimeZoneNameProviderImpl(getAdapterType(), TimeZoneNameProvider provider = new TimeZoneNameProviderImpl(getAdapterType(),
getLanguateTagSet("TimeZoneNames")); getLanguageTagSet("TimeZoneNames"));
synchronized (this) { synchronized (this) {
if (timeZoneNameProvider == null) { if (timeZoneNameProvider == null) {
timeZoneNameProvider = provider; timeZoneNameProvider = provider;
@ -253,8 +253,8 @@ public class JRELocaleProviderAdapter extends LocaleProviderAdapter {
public CalendarDataProvider getCalendarDataProvider() { public CalendarDataProvider getCalendarDataProvider() {
if (calendarDataProvider == null) { if (calendarDataProvider == null) {
Set<String> set = new HashSet<>(); Set<String> set = new HashSet<>();
set.addAll(getLanguateTagSet("FormatData")); set.addAll(getLanguageTagSet("FormatData"));
set.addAll(getLanguateTagSet("CalendarData")); set.addAll(getLanguageTagSet("CalendarData"));
CalendarDataProvider provider = new CalendarDataProviderImpl(getAdapterType(), CalendarDataProvider provider = new CalendarDataProviderImpl(getAdapterType(),
set); set);
synchronized (this) { synchronized (this) {
@ -302,7 +302,7 @@ public class JRELocaleProviderAdapter extends LocaleProviderAdapter {
return AvailableJRELocales.localeList.clone(); return AvailableJRELocales.localeList.clone();
} }
public Set<String> getLanguateTagSet(String category) { public Set<String> getLanguageTagSet(String category) {
Set<String> tagset = langtagSets.get(category); Set<String> tagset = langtagSets.get(category);
if (tagset == null) { if (tagset == null) {
tagset = createLanguageTagSet(category); tagset = createLanguageTagSet(category);

View File

@ -209,31 +209,26 @@ JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapte
*/ */
JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getDateTimePattern JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getDateTimePattern
(JNIEnv *env, jclass cls, jint dateStyle, jint timeStyle, jstring jlangtag) { (JNIEnv *env, jclass cls, jint dateStyle, jint timeStyle, jstring jlangtag) {
WCHAR datePattern[BUFLEN]; WCHAR pattern[BUFLEN];
WCHAR timePattern[BUFLEN];
const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE); const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
datePattern[0] = L'\0'; pattern[0] = L'\0';
timePattern[0] = L'\0';
if (dateStyle == 0 || dateStyle == 1) { if (dateStyle == 0 || dateStyle == 1) {
getLocaleInfoWrapper(langtag, LOCALE_SLONGDATE, datePattern, BUFLEN); getLocaleInfoWrapper(langtag, LOCALE_SLONGDATE, pattern, BUFLEN);
} else if (dateStyle == 2 || dateStyle == 3) { } else if (dateStyle == 2 || dateStyle == 3) {
getLocaleInfoWrapper(langtag, LOCALE_SSHORTDATE, datePattern, BUFLEN); getLocaleInfoWrapper(langtag, LOCALE_SSHORTDATE, pattern, BUFLEN);
} }
if (timeStyle == 0 || timeStyle == 1) { if (timeStyle == 0 || timeStyle == 1) {
getLocaleInfoWrapper(langtag, LOCALE_STIMEFORMAT, timePattern, BUFLEN); getLocaleInfoWrapper(langtag, LOCALE_STIMEFORMAT, pattern, BUFLEN);
} else if (timeStyle == 2 || timeStyle == 3) { } else if (timeStyle == 2 || timeStyle == 3) {
getLocaleInfoWrapper(langtag, LOCALE_SSHORTTIME, timePattern, BUFLEN); getLocaleInfoWrapper(langtag, LOCALE_SSHORTTIME, pattern, BUFLEN);
} }
wcscat(datePattern, L" ");
wcscat(datePattern, timePattern);
(*env)->ReleaseStringChars(env, jlangtag, langtag); (*env)->ReleaseStringChars(env, jlangtag, langtag);
return (*env)->NewString(env, datePattern, wcslen(datePattern)); return (*env)->NewString(env, pattern, wcslen(pattern));
} }
/* /*

View File

@ -20,27 +20,65 @@
* or visit www.oracle.com if you need additional information or have any * or visit www.oracle.com if you need additional information or have any
* questions. * questions.
*/ */
import java.text.spi.DateFormatProvider; import java.text.*;
import java.util.Locale; import java.text.spi.*;
import java.util.*;
import sun.util.locale.provider.LocaleProviderAdapter; 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) { String methodName = args[0];
// no args indicates that the caller is asking the platform default locale.
Locale defloc = Locale.getDefault(); switch (methodName) {
System.out.printf("%s,%s\n", defloc.getLanguage(), defloc.getCountry()); case "getPlatformLocale":
} else { if (args[1].equals("format")) {
String expected = args[0]; getPlatformLocale(Locale.Category.FORMAT);
Locale testLocale = new Locale(args[1], (args.length >= 3 ? args[2] : "")); } else {
String preference = System.getProperty("java.locale.providers", ""); getPlatformLocale(Locale.Category.DISPLAY);
LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, testLocale); }
LocaleProviderAdapter.Type type = lda.getAdapterType(); break;
System.out.printf("testLocale: %s, got: %s, expected: %s\n", testLocale, type, expected);
if (!type.toString().equals(expected)) { case "adapterTest":
throw new RuntimeException("Returned locale data adapter is not correct."); adapterTest(args[1], args[2], (args.length >= 4 ? args[3] : ""));
break;
case "bug7198834Test":
bug7198834Test();
break;
default:
throw new RuntimeException("Test method '"+methodName+"' not found.");
}
}
static void getPlatformLocale(Locale.Category cat) {
Locale defloc = Locale.getDefault(cat);
System.out.printf("%s,%s\n", defloc.getLanguage(), defloc.getCountry());
}
static void adapterTest(String expected, String lang, String ctry) {
Locale testLocale = new Locale(lang, ctry);
String preference = System.getProperty("java.locale.providers", "");
LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, testLocale);
LocaleProviderAdapter.Type type = lda.getAdapterType();
System.out.printf("testLocale: %s, got: %s, expected: %s\n", testLocale, type, expected);
if (!type.toString().equals(expected)) {
throw new RuntimeException("Returned locale data adapter is not correct.");
}
}
static void bug7198834Test() {
LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, Locale.US);
LocaleProviderAdapter.Type type = lda.getAdapterType();
if (type == LocaleProviderAdapter.Type.HOST && System.getProperty("os.name").startsWith("Windows")) {
DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);
String date = df.format(new Date());
if (date.charAt(date.length()-1) == ' ') {
throw new RuntimeException("Windows Host Locale Provider returns a trailing space.");
} }
} else {
System.out.println("Windows HOST locale adapter not found. Ignoring this test.");
} }
} }
} }

View File

@ -23,7 +23,7 @@
#!/bin/sh #!/bin/sh
# #
# @test # @test
# @bug 6336885 7196799 7197573 # @bug 6336885 7196799 7197573 7198834
# @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,16 +65,21 @@ case "$OS" in
;; ;;
esac esac
# get the platform default locale # get the platform default locales
PLATDEF=`${TESTJAVA}${FS}bin${FS}java -classpath ${TESTCLASSES} LocaleProviders` PLATDEF=`${TESTJAVA}${FS}bin${FS}java -classpath ${TESTCLASSES} LocaleProviders getPlatformLocale display`
DEFLANG=`echo ${PLATDEF} | sed -e "s/,.*//"` DEFLANG=`echo ${PLATDEF} | sed -e "s/,.*//"`
DEFCTRY=`echo ${PLATDEF} | sed -e "s/.*,//"` DEFCTRY=`echo ${PLATDEF} | sed -e "s/.*,//"`
echo "DEFLANG=${DEFLANG}" echo "DEFLANG=${DEFLANG}"
echo "DEFCTRY=${DEFCTRY}" echo "DEFCTRY=${DEFCTRY}"
PLATDEF=`${TESTJAVA}${FS}bin${FS}java -classpath ${TESTCLASSES} LocaleProviders getPlatformLocale format`
DEFFMTLANG=`echo ${PLATDEF} | sed -e "s/,.*//"`
DEFFMTCTRY=`echo ${PLATDEF} | sed -e "s/.*,//"`
echo "DEFFMTLANG=${DEFFMTLANG}"
echo "DEFFMTCTRY=${DEFFMTCTRY}"
runTest() runTest()
{ {
RUNCMD="${TESTJAVA}${FS}bin${FS}java -classpath ${TESTCLASSES} -Djava.locale.providers=$PREFLIST LocaleProviders $EXPECTED $TESTLANG $TESTCTRY" RUNCMD="${TESTJAVA}${FS}bin${FS}java -classpath ${TESTCLASSES} -Djava.locale.providers=$PREFLIST LocaleProviders $METHODNAME $PARAM1 $PARAM2 $PARAM3"
echo ${RUNCMD} echo ${RUNCMD}
${RUNCMD} ${RUNCMD}
result=$? result=$?
@ -88,91 +93,110 @@ 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
METHODNAME=adapterTest
PREFLIST=HOST,JRE PREFLIST=HOST,JRE
case "$OS" in case "$OS" in
Windows_NT* ) Windows_NT* )
WINVER=`uname -r` WINVER=`uname -r`
if [ "${WINVER}" = "5" ] if [ "${WINVER}" = "5" ]
then then
EXPECTED=JRE PARAM1=JRE
else else
EXPECTED=HOST PARAM1=HOST
fi fi
;; ;;
CYGWIN_NT-6* | Darwin ) CYGWIN_NT-6* | Darwin )
EXPECTED=HOST PARAM1=HOST
;; ;;
* ) * )
EXPECTED=JRE PARAM1=JRE
;; ;;
esac esac
TESTLANG=${DEFLANG} PARAM2=${DEFLANG}
TESTCTRY=${DEFCTRY} PARAM3=${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
METHODNAME=adapterTest
PREFLIST=HOST,JRE PREFLIST=HOST,JRE
EXPECTED=JRE PARAM1=JRE
if [ "${DEFLANG}" = "en" ] # Try to find the locale JRE supports which is not the platform default (HOST supports that one)
then if [ "${DEFLANG}" != "en" ] && [ "${DEFFMTLANG}" != "en" ]; then
TESTLANG=ja PARAM2=en
TESTCTRY=JP PARAM3=US
elif [ "${DEFLANG}" != "ja" ] && [ "${DEFFMTLANG}" != "ja" ]; then
PARAM2=ja
PARAM3=JP
else else
TESTLANG=en PARAM2=zh
TESTCTRY=US PARAM3=CN
fi fi
runTest runTest
# testing SPI is NOT selected, as there is none. # testing SPI is NOT selected, as there is none.
METHODNAME=adapterTest
PREFLIST=SPI,JRE PREFLIST=SPI,JRE
EXPECTED=JRE PARAM1=JRE
TESTLANG=en PARAM2=en
TESTCTRY=US PARAM3=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
METHODNAME=adapterTest
PREFLIST=CLDR,JRE PREFLIST=CLDR,JRE
EXPECTED=CLDR PARAM1=CLDR
TESTLANG=en PARAM2=en
TESTCTRY=GB PARAM3=GB
runTest runTest
# testing the order, variaton #2. This assumes en_GB DateFormat data are available both in JRE & CLDR # testing the order, variaton #2. This assumes en_GB DateFormat data are available both in JRE & CLDR
METHODNAME=adapterTest
PREFLIST=JRE,CLDR PREFLIST=JRE,CLDR
EXPECTED=JRE PARAM1=JRE
TESTLANG=en PARAM2=en
TESTCTRY=GB PARAM3=GB
runTest runTest
# testing the order, variaton #3 for non-existent locale in JRE assuming "haw" is not in JRE. # testing the order, variaton #3 for non-existent locale in JRE assuming "haw" is not in JRE.
METHODNAME=adapterTest
PREFLIST=JRE,CLDR PREFLIST=JRE,CLDR
EXPECTED=CLDR PARAM1=CLDR
TESTLANG=haw PARAM2=haw
TESTCTRY=GB PARAM3=GB
runTest runTest
# testing the order, variaton #4 for the bug 7196799. CLDR's "zh" data should be used in "zh_CN" # testing the order, variaton #4 for the bug 7196799. CLDR's "zh" data should be used in "zh_CN"
METHODNAME=adapterTest
PREFLIST=CLDR PREFLIST=CLDR
EXPECTED=CLDR PARAM1=CLDR
TESTLANG=zh PARAM2=zh
TESTCTRY=CN PARAM3=CN
runTest runTest
# testing FALLBACK provider. SPI and invalid one cases. # testing FALLBACK provider. SPI and invalid one cases.
METHODNAME=adapterTest
PREFLIST=SPI PREFLIST=SPI
EXPECTED=FALLBACK PARAM1=FALLBACK
TESTLANG=en PARAM2=en
TESTCTRY=US PARAM3=US
runTest runTest
PREFLIST=FOO PREFLIST=FOO
EXPECTED=JRE PARAM1=JRE
TESTLANG=en PARAM2=en
TESTCTRY=US PARAM3=US
runTest runTest
PREFLIST=BAR,SPI PREFLIST=BAR,SPI
EXPECTED=FALLBACK PARAM1=FALLBACK
TESTLANG=en PARAM2=en
TESTCTRY=US PARAM3=US
runTest
# testing 7198834 fix. Only works on Windows Vista or upper.
METHODNAME=bug7198834Test
PREFLIST=HOST
PARAM1=
PARAM2=
PARAM3=
runTest runTest
exit $result exit $result