changeset 3918:8216ad5fabb8

7023613: (lc) Incorrect string returned by Locale.toString() with non-empty script field Reviewed-by: srl
author naoto
date Fri, 11 Mar 2011 11:31:10 -0800
parents ed87479c96c2
children d901560d70a7
files src/share/classes/java/util/Locale.java test/java/util/Locale/LocaleEnhanceTest.java
diffstat 2 files changed, 19 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/Locale.java	Fri Mar 11 10:03:05 2011 -0800
+++ b/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/test/java/util/Locale/LocaleEnhanceTest.java	Fri Mar 11 10:03:05 2011 -0800
+++ b/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
     ///