mirror of
https://github.com/openjdk/jdk.git
synced 2026-07-18 15:09:37 +00:00
4940539: Constructor of java.util.Locale should handle ISO 639-2 Language Codes
Reviewed-by: okutsu
This commit is contained in:
parent
6d0bcba475
commit
c84359f622
@ -1449,10 +1449,15 @@ public final class Locale implements Cloneable, Serializable {
|
||||
* three-letter language abbreviation is not available for this locale.
|
||||
*/
|
||||
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) {
|
||||
throw new MissingResourceException("Couldn't find 3-letter language code for "
|
||||
+ _baseLocale.getLanguage(), "FormatData_" + toString(), "ShortLanguage");
|
||||
+ lang, "FormatData_" + toString(), "ShortLanguage");
|
||||
}
|
||||
return language3;
|
||||
}
|
||||
|
||||
@ -24,7 +24,8 @@
|
||||
* @test
|
||||
* @bug 4052404 4052440 4084688 4092475 4101316 4105828 4107014 4107953 4110613
|
||||
* 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
|
||||
*/
|
||||
/*
|
||||
@ -895,17 +896,28 @@ test commented out pending API-change approval
|
||||
}
|
||||
|
||||
/**
|
||||
* @bug 4147317
|
||||
* java.util.Locale.getISO3Language() works wrong for non ISO-3166 codes.
|
||||
* Should throw an exception for unknown locales
|
||||
* @bug 4147317 4940539
|
||||
* java.util.Locale.getISO3Language() works wrong for non ISO-639 codes.
|
||||
* Should throw an exception for unknown locales, except they have three
|
||||
* letter language codes.
|
||||
*/
|
||||
public void Test4147317() {
|
||||
// Try with codes that are the wrong length but happen to match text
|
||||
// at a valid offset in the mapping table
|
||||
// Try a three letter language code, and check whether it is
|
||||
// returned as is.
|
||||
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 {
|
||||
String result = locale.getISO3Language();
|
||||
result = locale.getISO3Language();
|
||||
|
||||
errln("ERROR: getISO3Language() returns: " + result +
|
||||
" for locale '" + locale + "' rather than exception" );
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user