From: remm Date: Thu, 26 Oct 2006 13:08:58 +0000 (+0000) Subject: - Refactor exception reporting using Throwable.getCause, since TC 6 does not have... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=cbbb689545c3ca572ba0e25d99a7f7ed0ae6d958;p=tomcat7.0 - Refactor exception reporting using Throwable.getCause, since TC 6 does not have the restrictions for modifications 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 --- diff --git a/java/javax/servlet/ServletException.java b/java/javax/servlet/ServletException.java index 59b4044c0..c13e77fd9 100644 --- a/java/javax/servlet/ServletException.java +++ b/java/javax/servlet/ServletException.java @@ -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 String * 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 String 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 Throwable * that caused this servlet exception - * */ - public Throwable getRootCause() { - return rootCause; + return getCause(); } } - - - - - diff --git a/java/org/apache/catalina/core/StandardWrapper.java b/java/org/apache/catalina/core/StandardWrapper.java index a08c22620..28e278cf2 100644 --- a/java/org/apache/catalina/core/StandardWrapper.java +++ b/java/org/apache/catalina/core/StandardWrapper.java @@ -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; } diff --git a/java/org/apache/catalina/valves/ErrorReportValve.java b/java/org/apache/catalina/valves/ErrorReportValve.java index 29b60066c..0c8b3c574 100644 --- a/java/org/apache/catalina/valves/ErrorReportValve.java +++ b/java/org/apache/catalina/valves/ErrorReportValve.java @@ -227,7 +227,8 @@ public class ErrorReportValve sb.append(RequestUtil.filter(stackTrace)); sb.append("

"); - while (rootCause != null) { + int loops = 0; + while (rootCause != null && (loops < 10)) { stackTrace = getPartialServletStackTrace(rootCause); sb.append("

"); sb.append(sm.getString("errorReportValve.rootCause")); @@ -235,12 +236,8 @@ public class ErrorReportValve sb.append(RequestUtil.filter(stackTrace)); sb.append("

"); // 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("

");