decouple logMissingProperties from devMode (WW-4999)

This commit is contained in:
Yasser Zamani
2019-06-01 12:52:22 +04:30
parent d4dd3386cc
commit 9e01fbd2dd
2 changed files with 4 additions and 13 deletions
@@ -182,8 +182,7 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS
private void trySetValue(String expr, Object value, boolean throwExceptionOnFailure, Map<String, Object> 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 {
@@ -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);