commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r890212 - in /commons/proper/lang/trunk/src: java/org/apache/commons/lang3/StringUtils.java test/org/apache/commons/lang3/StringUtilsTest.java
Date Mon, 14 Dec 2009 07:51:06 GMT
Author: bayard
Date: Mon Dec 14 07:51:05 2009
New Revision: 890212

URL: http://svn.apache.org/viewvc?rev=890212&view=rev
Log:
Applying fix for LANG-552. StringUtils.replaceEach(String, String[], String[]) no longer NPEs
when null appears in the last String[]

Modified:
    commons/proper/lang/trunk/src/java/org/apache/commons/lang3/StringUtils.java
    commons/proper/lang/trunk/src/test/org/apache/commons/lang3/StringUtilsTest.java

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang3/StringUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang3/StringUtils.java?rev=890212&r1=890211&r2=890212&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang3/StringUtils.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang3/StringUtils.java Mon Dec 14
07:51:05 2009
@@ -3673,6 +3673,9 @@
 
         // count the replacement text elements that are larger than their corresponding text
being replaced
         for (int i = 0; i < searchList.length; i++) {
+            if (searchList[i] == null || replacementList[i] == null) {
+                continue;
+            }
             int greater = replacementList[i].length() - searchList[i].length();
             if (greater > 0) {
                 increase += 3 * greater; // assume 3 matches

Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang3/StringUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang3/StringUtilsTest.java?rev=890212&r1=890211&r2=890212&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang3/StringUtilsTest.java (original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang3/StringUtilsTest.java Mon Dec
14 07:51:05 2009
@@ -1033,6 +1033,10 @@
                 "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "N", "O", "P",
"Q", 
                 "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "A", "B", "C", "D", "E", "F",
"G", 
                 "H", "I", "J", "K", "L", "M", "5", "6", "7", "8", "9", "1", "2", "3", "4"}));
+
+        // Test null safety inside arrays - LANG-552
+        assertEquals(StringUtils.replaceEach("aba", new String[]{"a"}, new String[]{null}),"aba");
+        assertEquals(StringUtils.replaceEach("aba", new String[]{"a", "b"}, new String[]{"c",
null}),"cbc");
     }
 
     /**



Mime
View raw message