You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/08/14 05:44:18 UTC

[commons-text] 02/02: [TEXT-186] StringSubstitutor map constructor throws NPE on 1.9 with null map.

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

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-text.git

commit 3c4d37d68a18aa5c93b95f27645c7589c58e54e8
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Aug 14 01:44:06 2020 -0400

    [TEXT-186] StringSubstitutor map constructor throws NPE on 1.9 with null
    map.
---
 src/changes/changes.xml                                             | 3 ++-
 .../java/org/apache/commons/text/lookup/FunctionStringLookup.java   | 3 ++-
 src/test/java/org/apache/commons/text/StringSubstitutorTest.java    | 6 ++++++
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index e07244a..8c410c7 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -45,7 +45,8 @@ The <action> type attribute can be add,update,fix,remove.
   </properties>
   <body>
   <release version="1.9.1" date="202Y-MM-DD" description="Release 1.9.1. Requires Java 8.">
-    <action issue="TEXT-158" type="fix" dev="kinow">Incorrect values for Jaccard similarity with empty strings</action>
+    <action issue="TEXT-158" type="fix" dev="kinow">Incorrect values for Jaccard similarity with empty strings.</action>
+    <action issue="TEXT-186" type="fix" dev="ggregory" due-to="Gautam Korlam, Gary Gregory">StringSubstitutor map constructor throws NPE on 1.9 with null map.</action>
     <action issue="TEXT-185" type="add" dev="ggregory" due-to="Larry West, Gary Gregory">Release Notes page hasn't been updated for 1.9 release yet.</action>    
     <action                  type="add" dev="ggregory" due-to="Gary Gregory, Dependabot">Update spotbugs.plugin.version 4.0.0 to 4.1.1, #144.</action>
     <action                  type="add" dev="ggregory" due-to="Dependabot">Update mockito-inline from 3.4.4 to 3.4.6 #143.</action>
diff --git a/src/main/java/org/apache/commons/text/lookup/FunctionStringLookup.java b/src/main/java/org/apache/commons/text/lookup/FunctionStringLookup.java
index ba158fc..50dd18d 100644
--- a/src/main/java/org/apache/commons/text/lookup/FunctionStringLookup.java
+++ b/src/main/java/org/apache/commons/text/lookup/FunctionStringLookup.java
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.text.lookup;
 
+import java.util.Collections;
 import java.util.Map;
 import java.util.Objects;
 import java.util.function.Function;
@@ -48,7 +49,7 @@ final class FunctionStringLookup<V> extends AbstractStringLookup {
      * @return a new instance backed by the given map.
      */
     static <V> FunctionStringLookup<V> on(final Map<String, V> map) {
-        return on(map::get);
+        return on((map == null ? Collections.<String, V>emptyMap() : map)::get);
     }
 
     /**
diff --git a/src/test/java/org/apache/commons/text/StringSubstitutorTest.java b/src/test/java/org/apache/commons/text/StringSubstitutorTest.java
index f7301b5..368440c 100644
--- a/src/test/java/org/apache/commons/text/StringSubstitutorTest.java
+++ b/src/test/java/org/apache/commons/text/StringSubstitutorTest.java
@@ -202,6 +202,12 @@ public class StringSubstitutorTest {
     }
 
     @Test
+    public void testConstructorNullMap() {
+        Map<String, Object> parameters = null;
+        final StringSubstitutor s = new StringSubstitutor(parameters, "prefix", "suffix");
+    }
+
+    @Test
     public void testConstructorStringSubstitutor() {
         final StringSubstitutor source = new StringSubstitutor();
         source.setDisableSubstitutionInValues(true);