“f77f33a1d50e747a485d705e39e01f7e3bef85b6”上不存在“...PlatformLoggingMXBean/PlatformLoggingMXBeanTest.java”
提交 ff61ddf5 编写于 作者: N naoto

4940539: Constructor of java.util.Locale should handle ISO 639-2 Language Codes

Reviewed-by: okutsu
上级 ba3e05b6
...@@ -1449,10 +1449,15 @@ public final class Locale implements Cloneable, Serializable { ...@@ -1449,10 +1449,15 @@ public final class Locale implements Cloneable, Serializable {
* three-letter language abbreviation is not available for this locale. * three-letter language abbreviation is not available for this locale.
*/ */
public String getISO3Language() throws MissingResourceException { public String getISO3Language() throws MissingResourceException {
String language3 = getISO3Code(_baseLocale.getLanguage(), LocaleISOData.isoLanguageTable); String lang = _baseLocale.getLanguage();
if (lang.length() == 3) {
return lang;
}
String language3 = getISO3Code(lang, LocaleISOData.isoLanguageTable);
if (language3 == null) { if (language3 == null) {
throw new MissingResourceException("Couldn't find 3-letter language code for " throw new MissingResourceException("Couldn't find 3-letter language code for "
+ _baseLocale.getLanguage(), "FormatData_" + toString(), "ShortLanguage"); + lang, "FormatData_" + toString(), "ShortLanguage");
} }
return language3; return language3;
} }
......
...@@ -24,7 +24,8 @@ ...@@ -24,7 +24,8 @@
* @test * @test
* @bug 4052404 4052440 4084688 4092475 4101316 4105828 4107014 4107953 4110613 * @bug 4052404 4052440 4084688 4092475 4101316 4105828 4107014 4107953 4110613
* 4118587 4118595 4122371 4126371 4126880 4135316 4135752 4139504 4139940 4143951 * 4118587 4118595 4122371 4126371 4126880 4135316 4135752 4139504 4139940 4143951
* 4147315 4147317 4147552 4335196 4778440 5010672 6475525 6544471 6627549 6786276 * 4147315 4147317 4147552 4335196 4778440 4940539 5010672 6475525 6544471 6627549
* 6786276
* @summary test Locales * @summary test Locales
*/ */
/* /*
...@@ -895,17 +896,28 @@ test commented out pending API-change approval ...@@ -895,17 +896,28 @@ test commented out pending API-change approval
} }
/** /**
* @bug 4147317 * @bug 4147317 4940539
* java.util.Locale.getISO3Language() works wrong for non ISO-3166 codes. * java.util.Locale.getISO3Language() works wrong for non ISO-639 codes.
* Should throw an exception for unknown locales * Should throw an exception for unknown locales, except they have three
* letter language codes.
*/ */
public void Test4147317() { public void Test4147317() {
// Try with codes that are the wrong length but happen to match text // Try a three letter language code, and check whether it is
// at a valid offset in the mapping table // returned as is.
Locale locale = new Locale("aaa", "CCC"); Locale locale = new Locale("aaa", "CCC");
String result = locale.getISO3Language();
if (!result.equals("aaa")) {
errln("ERROR: getISO3Language() returns: " + result +
" for locale '" + locale + "' rather than returning it as is" );
}
// Try an invalid two letter language code, and check whether it
// throws a MissingResourceException.
locale = new Locale("zz", "CCC");
try { try {
String result = locale.getISO3Language(); result = locale.getISO3Language();
errln("ERROR: getISO3Language() returns: " + result + errln("ERROR: getISO3Language() returns: " + result +
" for locale '" + locale + "' rather than exception" ); " for locale '" + locale + "' rather than exception" );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册