Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 3FE3B200B78 for ; Fri, 2 Sep 2016 14:00:26 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 3E576160AAC; Fri, 2 Sep 2016 12:00:26 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 85500160AAB for ; Fri, 2 Sep 2016 14:00:25 +0200 (CEST) Received: (qmail 38306 invoked by uid 500); 2 Sep 2016 12:00:24 -0000 Mailing-List: contact commits-help@struts.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@struts.apache.org Delivered-To: mailing list commits@struts.apache.org Received: (qmail 38297 invoked by uid 99); 2 Sep 2016 12:00:24 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Sep 2016 12:00:24 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 85D28E00D6; Fri, 2 Sep 2016 12:00:24 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: lukaszlenart@apache.org To: commits@struts.apache.org Message-Id: <9b723e8427c64a9f96a63a3d2fc6f0c7@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: struts git commit: WW-4663 Checks if expression is null to avoid NPE Date: Fri, 2 Sep 2016 12:00:24 +0000 (UTC) archived-at: Fri, 02 Sep 2016 12:00:26 -0000 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 Authored: Fri Sep 2 13:57:15 2016 +0200 Committer: Lukasz Lenart 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 {