[ofbiz-framework] branch release18.12 updated: Fixed: Possible NPE in StringUtil#strToMap (OFBIZ-11281)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[ofbiz-framework] branch release18.12 updated: Fixed: Possible NPE in StringUtil#strToMap (OFBIZ-11281)

nmalin
This is an automated email from the ASF dual-hosted git repository.

nmalin pushed a commit to branch release18.12
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/release18.12 by this push:
     new 5b4010f  Fixed: Possible NPE in StringUtil#strToMap (OFBIZ-11281)
5b4010f is described below

commit 5b4010f71640baaab7b091f388dcce1ea02fcdb1
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 c0f7eac..26e83a8 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
@@ -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"));