Fixed: Possible NPE in StringUtil#strToMap

(OFBIZ-11281)

StringUtil#strToMap(String, String, boolean, String) throws Nullpointer for StringUtil.strToMap("", false).

Thanks to Ulrich Heidfeld for this fix
This commit is contained in:
Nicolas Malin
2019-11-14 09:16:25 +01:00
parent 59b1ba17fa
commit 5b4010f716
2 changed files with 2 additions and 1 deletions
@@ -226,7 +226,7 @@ public class StringUtil {
* @return a Map of name/value pairs
*/
public static Map<String, String> strToMap(String str, String delim, boolean trim, String pairsSeparator) {
if (str == null) {
if (UtilValidate.isEmpty(str)) {
return null;
}
Map<String, String> decodedMap = new HashMap<>();
@@ -86,6 +86,7 @@ public class StringUtilTests extends GenericTestCaseBase {
public void testStrToMap() {
assertNull("null-string", StringUtil.strToMap(null, false));
assertNull("empty", StringUtil.strToMap("", false));
assertEquals("missing =", Collections.emptyMap(), StringUtil.strToMap("1", false));
assertEquals("single", map("1", "one"), StringUtil.strToMap("1=one"));
assertEquals("double", map("2", "two", "1", "one"), StringUtil.strToMap("1=one|2=two"));