changeset 3303:55d9205735e1

4940539: Constructor of java.util.Locale should handle ISO 639-2 Language Codes Reviewed-by: okutsu
author naoto
date Tue, 21 Dec 2010 16:14:14 -0800
parents 8da79c7d137e
children 403a88eeac15
files src/share/classes/java/util/Locale.java test/java/util/Locale/LocaleTest.java
diffstat 2 files changed, 26 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/Locale.java	Tue Dec 21 11:20:32 2010 +0900
+++ b/src/share/classes/java/util/Locale.java	Tue Dec 21 16:14:14 2010 -0800
@@ -1449,10 +1449,15 @@
      * 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;
     }
--- a/test/java/util/Locale/LocaleTest.java	Tue Dec 21 11:20:32 2010 +0900
+++ b/test/java/util/Locale/LocaleTest.java	Tue Dec 21 16:14:14 2010 -0800
@@ -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 @@
     }
 
     /**
-     * @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" );