Applying fix for LANG-552. StringUtils.replaceEach(String, String[], String[]) no longer NPEs when null appears in the last String[]
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@890212 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
dafb8e85dc
commit
56550bf277
|
@ -3673,6 +3673,9 @@ public class StringUtils {
|
|||
|
||||
// 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
|
||||
|
|
|
@ -1033,6 +1033,10 @@ public class StringUtilsTest extends TestCase {
|
|||
"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");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue