You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by br...@apache.org on 2014/01/03 11:26:55 UTC

svn commit: r1555043 - in /commons/proper/lang/trunk/src: changes/changes.xml main/java/org/apache/commons/lang3/LocaleUtils.java test/java/org/apache/commons/lang3/LocaleUtilsTest.java

Author: britter
Date: Fri Jan  3 10:26:54 2014
New Revision: 1555043

URL: http://svn.apache.org/r1555043
Log:
LANG-941: Test failure in LocaleUtilsTest when building with JDK 8

Modified:
    commons/proper/lang/trunk/src/changes/changes.xml
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/LocaleUtils.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java

Modified: commons/proper/lang/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/changes/changes.xml?rev=1555043&r1=1555042&r2=1555043&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/changes/changes.xml [utf-8] (original)
+++ commons/proper/lang/trunk/src/changes/changes.xml [utf-8] Fri Jan  3 10:26:54 2014
@@ -23,6 +23,7 @@
 
   <release version="3.2.1" date="TBA" description="Bug fix for 3.2">
     <action issue="LANG-937" type="fix" dev="britter">Fix missing Hamcrest dependency in Ant Build</action>
+    <action issue="LANG-941" type="fix" dev="britter">Test failure in LocaleUtilsTest when building with JDK 8</action>
   </release>
 
   <release version="3.2" date="2014-01-01" description="Bug fixes and new features, at least requires Java 6.0">

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/LocaleUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/LocaleUtils.java?rev=1555043&r1=1555042&r2=1555043&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/LocaleUtils.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/LocaleUtils.java Fri Jan  3 10:26:54 2014
@@ -65,6 +65,7 @@ public class LocaleUtils {
      * locale object from it.</p>
      *
      * <pre>
+     *   LocaleUtils.toLocale("")           = new Locale("", "")
      *   LocaleUtils.toLocale("en")         = new Locale("en", "")
      *   LocaleUtils.toLocale("en_GB")      = new Locale("en", "GB")
      *   LocaleUtils.toLocale("en_GB_xxx")  = new Locale("en", "GB", "xxx")   (#)
@@ -90,8 +91,8 @@ public class LocaleUtils {
         if (str == null) {
             return null;
         }
-        if (str.isEmpty()) {
-            throw new IllegalArgumentException("Cannot create locale from empty string");
+        if (str.isEmpty()) { // LANG-941 - JDK 8 introduced an empty locale where all fields are blank
+            return new Locale("", "");
         }
         if (str.contains("#")) { // LANG-879 - Cannot handle Java 7 script & extensions
             throw new IllegalArgumentException("Invalid locale format: " + str);

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java?rev=1555043&r1=1555042&r2=1555043&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java Fri Jan  3 10:26:54 2014
@@ -137,11 +137,9 @@ public class LocaleUtilsTest  {
         assertValidToLocale("zh");
         // Valid format but lang doesnt exist, should make instance anyway
         assertValidToLocale("qq");
-        
-        try {
-            LocaleUtils.toLocale("");
-            fail("Should fail if str is empty");
-        } catch (final IllegalArgumentException iae) {}
+        // LANG-941: JDK 8 introduced the empty locale as one of the default locales
+        assertValidToLocale("");
+
         try {
             LocaleUtils.toLocale("Us");
             fail("Should fail if not lowercase");