diff --git a/src/share/classes/java/util/Locale.java b/src/share/classes/java/util/Locale.java index efe200ed0dbad1eedbd14e5471626ace75b9252a..63c8b03c4d3726e1a44b85b1afc88a11e1e382a3 100644 --- a/src/share/classes/java/util/Locale.java +++ b/src/share/classes/java/util/Locale.java @@ -1168,7 +1168,7 @@ public final class Locale implements Cloneable, Serializable { 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 '_' } diff --git a/test/java/util/Locale/LocaleEnhanceTest.java b/test/java/util/Locale/LocaleEnhanceTest.java index 0ee6ed24dcae345e8b34aa7fb8a3ba08c6e8c10c..23445d5afc063a84aa5f8029120865389f29e3c8 100644 --- a/test/java/util/Locale/LocaleEnhanceTest.java +++ b/test/java/util/Locale/LocaleEnhanceTest.java @@ -43,7 +43,7 @@ import java.util.Set; /** * @test - * @bug 6875847 + * @bug 6875847 6992272 7002320 7015500 7023613 * @summary test API changes to Locale */ public class LocaleEnhanceTest extends LocaleTestFmwk { @@ -83,7 +83,7 @@ public class LocaleEnhanceTest extends LocaleTestFmwk { "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 class LocaleEnhanceTest extends LocaleTestFmwk { } } + 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 ///