jdk/src/share/classes/java/util/Locale.java
changeset 7809 bced84a279ec
parent 7513 7091fccbc86d
child 7783 8eb31199b5ed
--- a/jdk/src/share/classes/java/util/Locale.java	Wed Dec 22 18:30:34 2010 -0800
+++ b/jdk/src/share/classes/java/util/Locale.java	Wed Dec 22 23:12:17 2010 -0800
@@ -870,7 +870,7 @@
      * @throws SecurityException - if a security manager exists and its
      *     checkPermission method doesn't allow the operation.
      * @throws NullPointerException - if category and/or newLocale is null
-     * @see SecurityManager.checkPermission(java.security.Permission)
+     * @see SecurityManager#checkPermission(java.security.Permission)
      * @see PropertyPermission
      * @see #getDefault(Locale.Category)
      * @since 1.7
@@ -1232,20 +1232,18 @@
      * "Solaris_isjustthecoolestthing" is emitted as
      * "x-lvariant-Solaris", not as "solaris".</li></ul>
      *
-     * <p><b>Compatibility special cases:</b><ul>
+     * <p><b>Special Conversions:</b> Java supports some old locale
+     * representations, including deprecated ISO language codes,
+     * for compatibility. This method performs the following
+     * conversions:
+     * <ul>
      *
-     * <li>The language codes "iw", "ji", and "in" are handled
-     * specially. Java uses these deprecated codes for compatibility
-     * reasons. The <code>toLanguageTag</code> method converts these
-     * three codes (and only these three) to "he", "yi", and "id"
-     * respectively.
+     * <li>Deprecated ISO language codes "iw", "ji", and "in" are
+     * converted to "he", "yi", and "id", respectively.
      *
      * <li>A locale with language "no", country "NO", and variant
-     * "NY", representing Norwegian Nynorsk, will be represented as
-     * having language "nn", country "NO", and empty variant. This is
-     * because some JVMs used the deprecated form to represent the
-     * user's default locale, and for compatibility reasons that Take a has
-     * not been changed.</ul>
+     * "NY", representing Norwegian Nynorsk (Norway), is converted
+     * to a language tag "nn-NO".</li></ul>
      *
      * <p><b>Note:</b> Although the language tag created by this
      * method is well-formed (satisfies the syntax requirements
@@ -1327,7 +1325,7 @@
      *
      * <pre>
      *     Locale loc;
-     *     loc = Locale.forLanguageTag("en-US-x-lvariant-POSIX);
+     *     loc = Locale.forLanguageTag("en-US-x-lvariant-POSIX");
      *     loc.getVariant(); // returns "POSIX"
      *     loc.getExtension('x'); // returns null
      *
@@ -1355,10 +1353,10 @@
      * extensions are added as though the constructor had been called:
      *
      * <pre>
-     *    Locale.forLanguageTag("ja-JP-x-lvariant-JP).toLanguageTag();
-     *    // returns ja-JP-u-ca-japanese-x-lvariant-JP
-     *    Locale.forLanguageTag("th-TH-x-lvariant-TH).toLanguageTag();
-     *    // returns th-TH-u-nu-thai-x-lvariant-TH
+     *    Locale.forLanguageTag("ja-JP-x-lvariant-JP").toLanguageTag();
+     *    // returns "ja-JP-u-ca-japanese-x-lvariant-JP"
+     *    Locale.forLanguageTag("th-TH-x-lvariant-TH").toLanguageTag();
+     *    // returns "th-TH-u-nu-thai-x-lvariant-TH"
      * <pre></ul>
      *
      * <p>This implements the 'Language-Tag' production of BCP47, and
@@ -1428,7 +1426,12 @@
         LanguageTag tag = LanguageTag.parse(languageTag, null);
         InternalLocaleBuilder bldr = new InternalLocaleBuilder();
         bldr.setLanguageTag(tag);
-        return getInstance(bldr.getBaseLocale(), bldr.getLocaleExtensions());
+        BaseLocale base = bldr.getBaseLocale();
+        LocaleExtensions exts = bldr.getLocaleExtensions();
+        if (exts.isEmpty() && base.getVariant().length() > 0) {
+            exts = getCompatibilityExtensions(base.getLanguage(), base.getScript(), base.getRegion(), base.getVariant());
+        }
+        return getInstance(base, exts);
     }
 
     /**
@@ -2487,6 +2490,10 @@
         public Locale build() {
             BaseLocale baseloc = _locbld.getBaseLocale();
             LocaleExtensions extensions = _locbld.getLocaleExtensions();
+            if (extensions.isEmpty() && baseloc.getVariant().length() > 0) {
+                extensions = getCompatibilityExtensions(baseloc.getLanguage(), baseloc.getScript(),
+                        baseloc.getRegion(), baseloc.getVariant());
+            }
             return Locale.getInstance(baseloc, extensions);
         }
     }