This is an automated email from the ASF dual-hosted git repository.
nmalin pushed a commit to branch release17.12
in repository
https://gitbox.apache.org/repos/asf/ofbiz-framework.gitThe following commit(s) were added to refs/heads/release17.12 by this push:
new 372e68a Fixed: Possible NPE in StringUtil#strToMap (OFBIZ-11281)
372e68a is described below
commit 372e68a5e4fcf3204059084520851aa6ae2bcb99
Author: Nicolas Malin <
[hidden email]>
AuthorDate: Thu Nov 14 09:16:25 2019 +0100
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
---
framework/base/src/main/java/org/apache/ofbiz/base/util/StringUtil.java | 2 +-
.../src/main/java/org/apache/ofbiz/base/util/test/StringUtilTests.java | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/StringUtil.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/StringUtil.java
index daf39a4..717c5c9 100644
--- a/framework/base/src/main/java/org/apache/ofbiz/base/util/StringUtil.java
+++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/StringUtil.java
@@ -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<>();
diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/test/StringUtilTests.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/test/StringUtilTests.java
index a9fbc05..ba434cc 100644
--- a/framework/base/src/main/java/org/apache/ofbiz/base/util/test/StringUtilTests.java
+++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/test/StringUtilTests.java
@@ -87,6 +87,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"));