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:
@@ -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"));
|
||||
|
||||
Reference in New Issue
Block a user