Repository: struts Updated Branches: refs/heads/support-2-3 23e018132 -> cc0d52f21
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/cc0d52f2 Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/cc0d52f2 Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/cc0d52f2 Branch: refs/heads/support-2-3 Commit: cc0d52f216f97df296dd136b34af708c19a741ea Parents: 23e0181 Author: Lukasz Lenart <lukaszlen...@apache.org> Authored: Fri Sep 2 13:57:15 2016 +0200 Committer: Lukasz Lenart <lukaszlen...@apache.org> Committed: Fri Sep 2 13:57:15 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/cc0d52f2/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/cc0d52f2/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 {