commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r904158 - in /commons/proper/lang/branches/LANG_2_X/src: main/java/org/apache/commons/lang/StringUtils.java test/java/org/apache/commons/lang/StringUtilsTest.java
Date Thu, 28 Jan 2010 17:05:54 GMT
Author: niallp
Date: Thu Jan 28 17:05:54 2010
New Revision: 904158

URL: http://svn.apache.org/viewvc?rev=904158&view=rev
Log:
Port LANG-552 to 2.x branch - StringUtils.replaceEach(String, String[], String[]) no longer
NPEs when null appears in the last String[]

Modified:
    commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/StringUtils.java
    commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/StringUtilsTest.java

Modified: commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/StringUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/StringUtils.java?rev=904158&r1=904157&r2=904158&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/StringUtils.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/StringUtils.java
Thu Jan 28 17:05:54 2010
@@ -3727,6 +3727,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/branches/LANG_2_X/src/test/java/org/apache/commons/lang/StringUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/StringUtilsTest.java?rev=904158&r1=904157&r2=904158&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/StringUtilsTest.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/StringUtilsTest.java
Thu Jan 28 17:05:54 2010
@@ -1071,6 +1071,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