7023613: (lc) Incorrect string returned by Locale.toString() with non-empty script field
authornaoto
Fri, 11 Mar 2011 11:31:10 -0800
changeset 8780 c88e159a3e5c
parent 8779 d84abc7b455f
child 8781 1ecbd60a9024
7023613: (lc) Incorrect string returned by Locale.toString() with non-empty script field Reviewed-by: srl
jdk/src/share/classes/java/util/Locale.java
jdk/test/java/util/Locale/LocaleEnhanceTest.java
--- a/jdk/src/share/classes/java/util/Locale.java	Fri Mar 11 10:03:05 2011 -0800
+++ b/jdk/src/share/classes/java/util/Locale.java	Fri Mar 11 11:31:10 2011 -0800
@@ -1168,7 +1168,7 @@
         boolean e = (_extensions.getID().length() != 0);
 
         StringBuilder result = new StringBuilder(_baseLocale.getLanguage());
-        if (r || (l && v)) {
+        if (r || (l && (v || s || e))) {
             result.append('_')
                 .append(_baseLocale.getRegion()); // This may just append '_'
         }
--- a/jdk/test/java/util/Locale/LocaleEnhanceTest.java	Fri Mar 11 10:03:05 2011 -0800
+++ b/jdk/test/java/util/Locale/LocaleEnhanceTest.java	Fri Mar 11 11:31:10 2011 -0800
@@ -43,7 +43,7 @@
 
 /**
  * @test
- * @bug 6875847
+ * @bug 6875847 6992272 7002320 7015500 7023613
  * @summary test API changes to Locale
  */
 public class LocaleEnhanceTest extends LocaleTestFmwk {
@@ -83,7 +83,7 @@
             "en-Latn-US-NewYork", "en_US_NewYork_#Latn",
             "en-Latn-US", "en_US_#Latn",
             "en-Latn-NewYork", "en__NewYork_#Latn", // double underscore
-            "en-Latn", "en_#Latn",
+            "en-Latn", "en__#Latn", // double underscore
             "en-US-NewYork", "en_US_NewYork",
             "en-US", "en_US",
             "en-NewYork", "en__NewYork", // double underscore
@@ -1259,6 +1259,22 @@
         }
     }
 
+    public void testBug7023613() {
+        String[][] testdata = {
+            {"en-Latn", "en__#Latn"},
+            {"en-u-ca-japanese", "en__#u-ca-japanese"},
+        };
+
+        for (String[] data : testdata) {
+            String in = data[0];
+            String expected = (data.length == 1) ? data[0] : data[1];
+
+            Locale loc = Locale.forLanguageTag(in);
+            String out = loc.toString();
+            assertEquals("Empty country field with non-empty script/extension with input: " + in, expected, out);
+        }
+    }
+
     ///
     /// utility asserts
     ///