From 9e01fbd2ddeb6dd1962f76a3bd8af227d370762d Mon Sep 17 00:00:00 2001 From: Yasser Zamani Date: Sat, 1 Jun 2019 12:52:22 +0430 Subject: [PATCH] decouple logMissingProperties from devMode (WW-4999) --- .../com/opensymphony/xwork2/ognl/OgnlValueStack.java | 7 +++---- .../opensymphony/xwork2/ognl/OgnlValueStackTest.java | 10 +--------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java index 2116bdc4e..6bfdb31c9 100644 --- a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java +++ b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java @@ -182,8 +182,7 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS private void trySetValue(String expr, Object value, boolean throwExceptionOnFailure, Map context) throws OgnlException { context.put(XWorkConverter.CONVERSION_PROPERTY_FULLNAME, expr); - context.put(REPORT_ERRORS_ON_NO_PROP, throwExceptionOnFailure || (devMode && logMissingProperties) - ? Boolean.TRUE : Boolean.FALSE); + context.put(REPORT_ERRORS_ON_NO_PROP, throwExceptionOnFailure || logMissingProperties ? Boolean.TRUE : Boolean.FALSE); ognlUtil.setValue(expr, context, root, value); } @@ -247,7 +246,7 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS } protected void setupExceptionOnFailure(boolean throwExceptionOnFailure) { - if (throwExceptionOnFailure || (devMode && logMissingProperties)) { + if (throwExceptionOnFailure || logMissingProperties) { context.put(THROW_EXCEPTION_ON_FAILURE, true); } } @@ -342,7 +341,7 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS protected boolean shouldLogMissingPropertyWarning(OgnlException e) { return (e instanceof NoSuchPropertyException || (e instanceof MethodFailedException && e.getReason() instanceof NoSuchMethodException)) - && devMode && logMissingProperties; + && logMissingProperties; } private Object tryFindValue(String expr, Class asType) throws OgnlException { diff --git a/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java b/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java index 54b5ad725..f69fb7d98 100644 --- a/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java @@ -247,7 +247,6 @@ public class OgnlValueStackTest extends XWorkTestCase { public void testLogMissingProperties() { OgnlValueStack vs = createValueStack(); - vs.setDevMode("true"); vs.setLogMissingProperties("true"); Dog dog = new Dog(); @@ -278,7 +277,6 @@ public class OgnlValueStackTest extends XWorkTestCase { public void testNotLogUserExceptionsAsMissingProperties() { OgnlValueStack vs = createValueStack(); - vs.setDevMode("true"); vs.setLogMissingProperties("true"); Dog dog = new Dog(); @@ -300,13 +298,7 @@ public class OgnlValueStackTest extends XWorkTestCase { vs.findValue("getBite()", false); vs.findValue("getBite()", void.class, false); - assertEquals(8, testAppender.logEvents.size()); - for (int i = 0; i < testAppender.logEvents.size(); i += 2) { - assertTrue(testAppender.logEvents.get(i).getMessage().getFormattedMessage() - .startsWith("Caught an exception while evaluating expression '")); - assertEquals("NOTE: Previous warning message was issued due to devMode set to true.", - testAppender.logEvents.get(i + 1).getMessage().getFormattedMessage()); - } + assertEquals(0, testAppender.logEvents.size()); } finally { testAppender.stop(); logger.removeAppender(testAppender);