mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
not log user exceptions as missing properties (WW-4999)
Also reaks loop on user method exceptions - but continue to next objects in stack on NoSuchMethodException.
This commit is contained in:
@@ -340,7 +340,8 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS
|
||||
}
|
||||
|
||||
protected boolean shouldLogMissingPropertyWarning(OgnlException e) {
|
||||
return (e instanceof NoSuchPropertyException || e instanceof MethodFailedException)
|
||||
return (e instanceof NoSuchPropertyException ||
|
||||
(e instanceof MethodFailedException && e.getReason() instanceof NoSuchMethodException))
|
||||
&& devMode && logMissingProperties;
|
||||
}
|
||||
|
||||
|
||||
@@ -218,13 +218,13 @@ public class CompoundRootAccessor implements PropertyAccessor, MethodAccessor, C
|
||||
}
|
||||
|
||||
Throwable reason = null;
|
||||
Class[] argTypes = getArgTypes(objects);
|
||||
for (Object o : root) {
|
||||
if (o == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Class clazz = o.getClass();
|
||||
Class[] argTypes = getArgTypes(objects);
|
||||
|
||||
MethodCall mc = null;
|
||||
|
||||
@@ -236,12 +236,17 @@ public class CompoundRootAccessor implements PropertyAccessor, MethodAccessor, C
|
||||
try {
|
||||
return OgnlRuntime.callMethod((OgnlContext) context, o, name, objects);
|
||||
} catch (OgnlException e) {
|
||||
// try the next one
|
||||
reason = e.getReason();
|
||||
|
||||
if ((mc != null) && (reason != null) && (reason.getClass() == NoSuchMethodException.class)) {
|
||||
if (reason != null && !(reason instanceof NoSuchMethodException)) {
|
||||
// method has found but thrown an exception
|
||||
break;
|
||||
}
|
||||
|
||||
if ((mc != null) && (reason != null)) {
|
||||
invalidMethods.put(mc, Boolean.TRUE);
|
||||
}
|
||||
// continue and try the next one
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,6 +276,43 @@ public class OgnlValueStackTest extends XWorkTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testNotLogUserExceptionsAsMissingProperties() {
|
||||
OgnlValueStack vs = createValueStack();
|
||||
vs.setDevMode("true");
|
||||
vs.setLogMissingProperties("true");
|
||||
|
||||
Dog dog = new Dog();
|
||||
vs.push(dog);
|
||||
|
||||
TestAppender testAppender = new TestAppender();
|
||||
Logger logger = (Logger) LogManager.getLogger(OgnlValueStack.class);
|
||||
logger.addAppender(testAppender);
|
||||
testAppender.start();
|
||||
|
||||
try {
|
||||
vs.setValue("exception", "exceptionValue", false);
|
||||
vs.findValue("exception", false);
|
||||
vs.findValue("exception", String.class, false);
|
||||
vs.findValue("getException()", false);
|
||||
vs.findValue("getException()", String.class, false);
|
||||
vs.findValue("bite", false);
|
||||
vs.findValue("bite", void.class, false);
|
||||
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());
|
||||
}
|
||||
} finally {
|
||||
testAppender.stop();
|
||||
logger.removeAppender(testAppender);
|
||||
}
|
||||
}
|
||||
|
||||
public void testFailOnMissingMethod() {
|
||||
OgnlValueStack vs = createValueStack();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user