struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject struts git commit: WW-4663 Checks if expression is null to avoid NPE
Date Fri, 02 Sep 2016 12:00:24 GMT
Repository: struts
Updated Branches:
  refs/heads/master 92c54de11 -> 7dbe3ea8b


WW-4663 Checks if expression is null to avoid NPE


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/7dbe3ea8
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/7dbe3ea8
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/7dbe3ea8

Branch: refs/heads/master
Commit: 7dbe3ea8bb97cd004e77541c761bbe20e4373c3d
Parents: 92c54de
Author: Lukasz Lenart <lukaszlenart@apache.org>
Authored: Fri Sep 2 13:57:15 2016 +0200
Committer: Lukasz Lenart <lukaszlenart@apache.org>
Committed: Fri Sep 2 14:00:17 2016 +0200

----------------------------------------------------------------------
 .../main/java/org/apache/struts2/util/ComponentUtils.java    | 4 ++--
 .../java/org/apache/struts2/util/ComponentUtilsTest.java     | 8 ++++++++
 2 files changed, 10 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/7dbe3ea8/core/src/main/java/org/apache/struts2/util/ComponentUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/util/ComponentUtils.java b/core/src/main/java/org/apache/struts2/util/ComponentUtils.java
index 01fbcd9..054038f 100644
--- a/core/src/main/java/org/apache/struts2/util/ComponentUtils.java
+++ b/core/src/main/java/org/apache/struts2/util/ComponentUtils.java
@@ -44,11 +44,11 @@ public class ComponentUtils {
      * @return true if it is an expression
      */
     public static boolean isExpression(String expr) {
-        return expr.startsWith("%{") && expr.endsWith("}");
+        return expr != null && expr.startsWith("%{") && expr.endsWith("}");
     }
 
     public static boolean containsExpression(String expr) {
-        return expr.contains("%{") && expr.contains("}");
+        return expr != null && expr.contains("%{") && expr.contains("}");
     }
 
 }

http://git-wip-us.apache.org/repos/asf/struts/blob/7dbe3ea8/core/src/test/java/org/apache/struts2/util/ComponentUtilsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/util/ComponentUtilsTest.java b/core/src/test/java/org/apache/struts2/util/ComponentUtilsTest.java
index 095176a..1e05ebd 100644
--- a/core/src/test/java/org/apache/struts2/util/ComponentUtilsTest.java
+++ b/core/src/test/java/org/apache/struts2/util/ComponentUtilsTest.java
@@ -93,6 +93,10 @@ public class ComponentUtilsTest extends StrutsInternalTestCase {
         assertFalse(actual);
     }
 
+    public void testIsExpressionIsFalseWhenNull() throws Exception {
+        assertFalse(ComponentUtils.isExpression(null));
+    }
+
     public void testContainsExpressionIsTrue() throws Exception {
         // given
         String anExpression = "%{foo}";
@@ -125,6 +129,10 @@ public class ComponentUtilsTest extends StrutsInternalTestCase {
         // then
         assertFalse(actual);
     }
+
+    public void testContainsExpressionIsFalseWhenNull() throws Exception {
+        assertFalse(ComponentUtils.containsExpression(null));
+    }
 }
 
 class MockConfigurationProvider implements ConfigurationProvider {


Mime
View raw message