From 2cba188601a3b49a712574b0e57b5c51f07d3070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Gielen?= Date: Sat, 7 Sep 2013 13:26:25 +0000 Subject: [PATCH] WW-4193 - Patch by Christoph Nenning With this patch it is checked if devMode is active and if logMissingProperties is enabled before the exception is logged - refactored shouldLogNoSuchPropertyWarning() to shouldLogMissingPropertyWarning() and using it to handle MethodFailedExceptions. - updated void handleOgnlException(String expr, Object value, boolean throwExceptionOnFailure, OgnlException e) to use it. git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1520763 13f79535-47bb-0310-9956-ffa450edef68 --- .../xwork2/ognl/OgnlValueStack.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java index 10082293b..138db581a 100644 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java +++ b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java @@ -203,10 +203,15 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS } private void handleOgnlException(String expr, Object value, boolean throwExceptionOnFailure, OgnlException e) { - String msg = "Error setting expression '" + expr + "' with value '" + value + "'"; - if (LOG.isWarnEnabled()) { + boolean shouldLog = shouldLogMissingPropertyWarning(e); + String msg = null; + if (throwExceptionOnFailure || shouldLog) { + msg = "Error setting expression '" + expr + "' with value '" + value + "'"; + } + if (shouldLog) { LOG.warn(msg, e); - } + } + if (throwExceptionOnFailure) { throw new XWorkException(msg, e); } @@ -320,7 +325,7 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS private Object handleOgnlException(String expr, boolean throwExceptionOnFailure, OgnlException e) { Object ret = findInContext(expr); if (ret == null) { - if (shouldLogNoSuchPropertyWarning(e)) { + if (shouldLogMissingPropertyWarning(e)) { LOG.warn("Could not find property [" + ((NoSuchPropertyException) e).getName() + "]"); } if (throwExceptionOnFailure) { @@ -330,8 +335,9 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS return ret; } - private boolean shouldLogNoSuchPropertyWarning(OgnlException e) { - return e instanceof NoSuchPropertyException && devMode && logMissingProperties; + private boolean shouldLogMissingPropertyWarning(OgnlException e) { + return (e instanceof NoSuchPropertyException || e instanceof MethodFailedException) + && devMode && logMissingProperties; } private Object tryFindValue(String expr, Class asType) throws OgnlException {