Author: remm Date: Thu Oct 26 06:08:58 2006 New Revision: 467989 URL: http://svn.apache.org/viewvc?view=rev&rev=467989 Log: - 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.
Modified: tomcat/tc6.0.x/trunk/java/javax/servlet/ServletException.java tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardWrapper.java tomcat/tc6.0.x/trunk/java/org/apache/catalina/valves/ErrorReportValve.java Modified: tomcat/tc6.0.x/trunk/java/javax/servlet/ServletException.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/javax/servlet/ServletException.java?view=diff&rev=467989&r1=467988&r2=467989 ============================================================================== --- tomcat/tc6.0.x/trunk/java/javax/servlet/ServletException.java (original) +++ tomcat/tc6.0.x/trunk/java/javax/servlet/ServletException.java Thu Oct 26 06:08:58 2006 @@ -23,30 +23,15 @@ * * @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 @@ * @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 @@ * 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 @@ * 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 @@ * 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(); } } - - - - - Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardWrapper.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardWrapper.java?view=diff&rev=467989&r1=467988&r2=467989 ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardWrapper.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardWrapper.java Thu Oct 26 06:08:58 2006 @@ -679,17 +679,13 @@ 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; } Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/valves/ErrorReportValve.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/valves/ErrorReportValve.java?view=diff&rev=467989&r1=467988&r2=467989 ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/catalina/valves/ErrorReportValve.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/valves/ErrorReportValve.java Thu Oct 26 06:08:58 2006 @@ -227,7 +227,8 @@ 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 @@ 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>"); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]