diff --git a/src/java/org/apache/commons/lang/LocaleUtils.java b/src/java/org/apache/commons/lang/LocaleUtils.java index 437594850..e41d9f011 100644 --- a/src/java/org/apache/commons/lang/LocaleUtils.java +++ b/src/java/org/apache/commons/lang/LocaleUtils.java @@ -70,11 +70,15 @@ public class LocaleUtils { * locale object from it.

* *
-     *   LocaleUtils.toLocale("en")     = new Locale("en", "")
-     *   LocaleUtils.toLocale("en_GB")  = new Locale("en", "GB")
-     *   LocaleUtils.toLocale("en_GB_xxx")  = new Locale("en", "GB", "xxx")
+     *   LocaleUtils.toLocale("en")         = new Locale("en", "")
+     *   LocaleUtils.toLocale("en_GB")      = new Locale("en", "GB")
+     *   LocaleUtils.toLocale("en_GB_xxx")  = new Locale("en", "GB", "xxx")   (#)
      * 
- * + * + *

(#) The behaviour of the JDK variant constructor changed between JDK1.3 and JDK1.4. + * In JDK1.3, the constructor upper cases the variant, in JDK1.4, it doesn't. + * Thus, the result from getVariant() may vary depending on your JDK.

+ * *

This method validates the input strictly. * The language code must be lowercase. * The country code must be uppercase. diff --git a/src/test/org/apache/commons/lang/LocaleUtilsTest.java b/src/test/org/apache/commons/lang/LocaleUtilsTest.java index 22cb703ec..52c78c82e 100644 --- a/src/test/org/apache/commons/lang/LocaleUtilsTest.java +++ b/src/test/org/apache/commons/lang/LocaleUtilsTest.java @@ -220,9 +220,16 @@ public class LocaleUtilsTest extends TestCase { * Test toLocale() method. */ public void testToLocale_3Part() { - assertValidToLocale("us_EN_a", "us", "EN", "a"); assertValidToLocale("us_EN_A", "us", "EN", "A"); - assertValidToLocale("us_EN_SFsafdFDsdfF", "us", "EN", "SFsafdFDsdfF"); + // this isn't pretty, but was caused by a jdk bug it seems + // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4210525 + if (SystemUtils.isJavaVersionAtLeast(1.4f)) { + assertValidToLocale("us_EN_a", "us", "EN", "a"); + assertValidToLocale("us_EN_SFsafdFDsdfF", "us", "EN", "SFsafdFDsdfF"); + } else { + assertValidToLocale("us_EN_a", "us", "EN", "A"); + assertValidToLocale("us_EN_SFsafdFDsdfF", "us", "EN", "SFSAFDFDSDFF"); + } try { LocaleUtils.toLocale("us_EN-a"); @@ -272,7 +279,7 @@ public class LocaleUtilsTest extends TestCase { new Locale[] { LOCALE_EN_US_ZZZZ, LOCALE_EN_US, - new Locale("en", "")}); + LOCALE_EN}); } /**