Skip to content
Browse files

Fixed: Possible NPE in StringUtil#strToMap


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

Thanks to Ulrich Heidfeld for this fix
  • Loading branch information
nmalin committed Nov 14, 2019
1 parent 18d84ac commit 935ffe86ca991ae0a1ed3e4f45c7f37006ca4a05
@@ -158,7 +158,7 @@ public static String join(Collection<?> col, CharSequence delim) {
* @return a Map of name/value pairs
private 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<>();
@@ -73,6 +73,7 @@ public void testSplit() {
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", UtilMisc.toMap("1", "one"), StringUtil.strToMap("1=one"));
assertEquals("double", UtilMisc.toMap("2", "two", "1", "one"), StringUtil.strToMap("1=one|2=two"));

0 comments on commit 935ffe8

Please sign in to comment.
You can’t perform that action at this time.