- Refactor exception reporting using Throwable.getCause, since TC 6 does not have...
authorremm <remm@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 26 Oct 2006 13:08:58 +0000 (13:08 +0000)
committerremm <remm@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 26 Oct 2006 13:08:58 +0000 (13:08 +0000)
  to the API implementation classes.
- ServletException.getRootCause now calls getCause.
- Also add some tweaks for robustness to cap recursion.
- Let me know if I did it wrong.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@467989 13f79535-47bb-0310-9956-ffa450edef68

java/javax/servlet/ServletException.java
java/org/apache/catalina/core/StandardWrapper.java
java/org/apache/catalina/valves/ErrorReportValve.java

index 59b4044..c13e77f 100644 (file)
@@ -23,30 +23,15 @@ package javax.servlet;
  *
  * @author     Various
  * @version    $Version$
- *
  */
-
-
 public class ServletException extends Exception {
 
-    private Throwable rootCause;
-
-
-
-
-
     /**
      * Constructs a new servlet exception.
-     *
      */
-
     public ServletException() {
-       super();
+        super();
     }
-    
-   
-
-    
 
     /**
      * Constructs a new servlet exception with the
@@ -56,16 +41,10 @@ public class ServletException extends Exception {
      * @param message          a <code>String</code> 
      *                         specifying the text of 
      *                         the exception message
-     *
      */
-
     public ServletException(String message) {
-       super(message);
+        super(message);
     }
-    
-   
-   
-    
 
     /**
      * Constructs a new servlet exception when the servlet 
@@ -73,7 +52,6 @@ public class ServletException extends Exception {
      * about the "root cause" exception that interfered with its 
      * normal operation, including a description message.
      *
-     *
      * @param message          a <code>String</code> containing 
      *                         the text of the exception message
      *
@@ -81,18 +59,11 @@ public class ServletException extends Exception {
      *                         that interfered with the servlet's
      *                         normal operation, making this servlet
      *                         exception necessary
-     *
      */
-    
     public ServletException(String message, Throwable rootCause) {
-       super(message);
-       this.rootCause = rootCause;
+        super(message, rootCause);
     }
 
-
-
-
-
     /**
      * Constructs a new servlet exception when the servlet 
      * needs to throw an exception and include a message
@@ -110,33 +81,18 @@ public class ServletException extends Exception {
      *                                 that interfered with the servlet's
      *                         normal operation, making the servlet exception
      *                         necessary
-     *
      */
-
     public ServletException(Throwable rootCause) {
-       super(rootCause.getLocalizedMessage());
-       this.rootCause = rootCause;
+        this(rootCause.getLocalizedMessage(), rootCause);
     }
-  
-  
-    
+
     /**
      * Returns the exception that caused this servlet exception.
      *
-     *
      * @return                 the <code>Throwable</code> 
      *                         that caused this servlet exception
-     *
      */
-    
     public Throwable getRootCause() {
-       return rootCause;
+        return getCause();
     }
 }
-
-
-
-
-
index a08c226..28e278c 100644 (file)
@@ -679,17 +679,13 @@ public class StandardWrapper
         Throwable rootCause = e;
         Throwable rootCauseCheck = null;
         // Extra aggressive rootCause finding
+        int loops = 0;
         do {
-            try {
-                rootCauseCheck = (Throwable)IntrospectionUtils.getProperty
-                                            (rootCause, "rootCause");
-                if (rootCauseCheck!=null)
-                    rootCause = rootCauseCheck;
-
-            } catch (ClassCastException ex) {
-                rootCauseCheck = null;
-            }
-        } while (rootCauseCheck != null);
+            loops++;
+            rootCauseCheck = rootCause.getCause();
+            if (rootCauseCheck != null)
+                rootCause = rootCauseCheck;
+        } while (rootCauseCheck != null && (loops < 20));
         return rootCause;
     }
 
index 29b6006..0c8b3c5 100644 (file)
@@ -227,7 +227,8 @@ public class ErrorReportValve
             sb.append(RequestUtil.filter(stackTrace));
             sb.append("</pre></p>");
 
-            while (rootCause != null) {
+            int loops = 0;
+            while (rootCause != null && (loops < 10)) {
                 stackTrace = getPartialServletStackTrace(rootCause);
                 sb.append("<p><b>");
                 sb.append(sm.getString("errorReportValve.rootCause"));
@@ -235,12 +236,8 @@ public class ErrorReportValve
                 sb.append(RequestUtil.filter(stackTrace));
                 sb.append("</pre></p>");
                 // In case root cause is somehow heavily nested
-                try {
-                    rootCause = (Throwable)IntrospectionUtils.getProperty
-                                                (rootCause, "rootCause");
-                } catch (ClassCastException e) {
-                    rootCause = null;
-                }
+                rootCause = rootCause.getCause();
+                loops++;
             }
 
             sb.append("<p><b>");