patrickl 2002/08/15 16:51:14
Modified: catalina/src/share/org/apache/catalina/valves
ErrorDispatcherValve.java
Log:
If a Servlet generates a RuntimeException, it is wrapped by a ServletException.
Since there is an entry for ServletException in the web.xml, the actual root cause (in
this case, an IllegalStateException) was never unwrapped, thus leading to unexpected
behavior.
I made a simple modification to the logic so that if the throwable passed to the
ErrorDispatcherValve is a ServletException, it will attempt to get the root cause. If
the root cause is null, then proceed with the error page lookup with the
ServletException as the throwable object, otherwise, use the root cause for the error
page lookup.
Submitted by: Ryan Lubke ([EMAIL PROTECTED])
Revision Changes Path
1.9 +14 -14
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/valves/ErrorDispatcherValve.java
Index: ErrorDispatcherValve.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/valves/ErrorDispatcherValve.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ErrorDispatcherValve.java 2 Dec 2001 22:19:26 -0000 1.8
+++ ErrorDispatcherValve.java 15 Aug 2002 23:51:14 -0000 1.9
@@ -212,20 +212,20 @@
*/
protected void throwable(Request request, Response response,
Throwable throwable) {
-
Context context = request.getContext();
if (context == null)
return;
-
+
Throwable realError = throwable;
- ErrorPage errorPage = findErrorPage(context, realError);
- if ((errorPage == null) && (realError instanceof ServletException)) {
+
+ if (realError instanceof ServletException) {
realError = ((ServletException) realError).getRootCause();
- if (realError != null)
- errorPage = findErrorPage(context, realError);
- else
+ if (realError == null) {
realError = throwable;
- }
+ }
+ }
+
+ ErrorPage errorPage = findErrorPage(context, realError);
if (errorPage != null) {
response.setAppCommitted(false);
@@ -237,7 +237,7 @@
sreq.setAttribute(Globals.ERROR_MESSAGE_ATTR,
throwable.getMessage());
sreq.setAttribute(Globals.EXCEPTION_ATTR,
- throwable);
+ realError);
Wrapper wrapper = request.getWrapper();
if (wrapper != null)
sreq.setAttribute(Globals.SERVLET_NAME_ATTR,
@@ -246,7 +246,7 @@
sreq.setAttribute(Globals.EXCEPTION_PAGE_ATTR,
((HttpServletRequest) sreq).getRequestURI());
sreq.setAttribute(Globals.EXCEPTION_TYPE_ATTR,
- throwable.getClass());
+ realError.getClass());
if (custom(request, response, errorPage)) {
try {
sresp.flushBuffer();
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>