mirror of
https://github.com/apache/struts.git
synced 2026-08-31 11:24:28 +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) {
|
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;
|
&& devMode && logMissingProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -218,13 +218,13 @@ public class CompoundRootAccessor implements PropertyAccessor, MethodAccessor, C
|
|||||||
}
|
}
|
||||||
|
|
||||||
Throwable reason = null;
|
Throwable reason = null;
|
||||||
|
Class[] argTypes = getArgTypes(objects);
|
||||||
for (Object o : root) {
|
for (Object o : root) {
|
||||||
if (o == null) {
|
if (o == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Class clazz = o.getClass();
|
Class clazz = o.getClass();
|
||||||
Class[] argTypes = getArgTypes(objects);
|
|
||||||
|
|
||||||
MethodCall mc = null;
|
MethodCall mc = null;
|
||||||
|
|
||||||
@@ -236,12 +236,17 @@ public class CompoundRootAccessor implements PropertyAccessor, MethodAccessor, C
|
|||||||
try {
|
try {
|
||||||
return OgnlRuntime.callMethod((OgnlContext) context, o, name, objects);
|
return OgnlRuntime.callMethod((OgnlContext) context, o, name, objects);
|
||||||
} catch (OgnlException e) {
|
} catch (OgnlException e) {
|
||||||
// try the next one
|
|
||||||
reason = e.getReason();
|
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);
|
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() {
|
public void testFailOnMissingMethod() {
|
||||||
OgnlValueStack vs = createValueStack();
|
OgnlValueStack vs = createValueStack();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user