Given the following:

web.xml with error-page entries for the following Exception types:

   - IllegalStateException
   - ServletException

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.

I've tested this using my own tests as well as those that Watchdog 4.0
has for this area as well, and all seems OK.

If I missed something here, please let me know.  I'm struggling to stay
awake here :)

-rl

PS.  I've attached some very simple patches for some javadoc warnings I
noticed during the build process.


Index: ErrorDispatcherValve.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/valves/ErrorDispatcherValve.java,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 ErrorDispatcherValve.java
--- ErrorDispatcherValve.java	18 Jul 2002 16:47:42 -0000	1.1.1.1
+++ ErrorDispatcherValve.java	14 Aug 2002 03:04:47 -0000
@@ -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();
Index: Node.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Node.java,v
retrieving revision 1.23
diff -u -r1.23 Node.java
--- Node.java	31 Jul 2002 21:42:27 -0000	1.23
+++ Node.java	14 Aug 2002 03:06:57 -0000
@@ -291,7 +291,7 @@
 	}
 
 	/**
-	 * @ return The enclosing root to this root.  Usually represents the
+	 * @return The enclosing root to this root.  Usually represents the
 	 * page that includes this one.
 	 */
 	public Root getParentRoot() {
Index: BodyContentImpl.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime/BodyContentImpl.java,v
retrieving revision 1.4
diff -u -r1.4 BodyContentImpl.java
--- BodyContentImpl.java	10 Jun 2002 20:12:27 -0000	1.4
+++ BodyContentImpl.java	14 Aug 2002 03:07:57 -0000
@@ -518,7 +518,7 @@
      * Note: this is after evaluation!!  There are no scriptlets,
      * etc in this stream.
      *
-     * @returns the value of this BodyJspWriter as a Reader
+     * @return the value of this BodyJspWriter as a Reader
      */
     public Reader getReader() {
         return new CharArrayReader (cb, 0, nextChar);
@@ -529,7 +529,7 @@
      * Note: this is after evaluation!!  There are no scriptlets,
      * etc in this stream.
      *
-     * @returns the value of the BodyJspWriter as a String
+     * @return the value of the BodyJspWriter as a String
      */
     public String getString() {
         return new String(cb, 0, nextChar);

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to