Author: markt Date: Fri Jan 19 18:47:25 2007 New Revision: 498049 URL: http://svn.apache.org/viewvc?view=rev&rev=498049 Log: Improved patch for 39088 based on patch by Wouter Zelle.
Modified: tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/core/StandardWrapper.java tomcat/container/tc5.5.x/webapps/docs/changelog.xml Modified: tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/core/StandardWrapper.java URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/core/StandardWrapper.java?view=diff&rev=498049&r1=498048&r2=498049 ============================================================================== --- tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/core/StandardWrapper.java (original) +++ tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/core/StandardWrapper.java Fri Jan 19 18:47:25 2007 @@ -28,6 +28,8 @@ import java.security.AccessController; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; +import java.sql.SQLException; + import javax.servlet.Servlet; import javax.servlet.ServletConfig; import javax.servlet.ServletContext; @@ -36,6 +38,7 @@ import javax.servlet.ServletResponse; import javax.servlet.SingleThreadModel; import javax.servlet.UnavailableException; +import javax.servlet.jsp.JspException; import javax.management.ListenerNotFoundException; import javax.management.MBeanNotificationInfo; import javax.management.Notification; @@ -56,7 +59,6 @@ import org.apache.catalina.security.SecurityUtil; import org.apache.catalina.util.Enumerator; import org.apache.catalina.util.InstanceSupport; -import org.apache.tomcat.util.IntrospectionUtils; import org.apache.tomcat.util.log.SystemLogHandler; import org.apache.commons.modeler.Registry; @@ -632,23 +634,33 @@ * @param e The servlet exception */ public static Throwable getRootCause(ServletException e) { - Throwable rootCause = e; - Throwable rootCauseCheck = null; - // Extra aggressive rootCause finding - do { - try { - rootCauseCheck = (Throwable)IntrospectionUtils.getProperty - (rootCause, "rootCause"); - if (rootCause == rootCauseCheck) - rootCauseCheck = null; - else if (rootCauseCheck != null) - rootCause = rootCauseCheck; + Throwable rootCause = e.getRootCause(); + return findRootCause(e, rootCause); + } - } catch (ClassCastException ex) { - rootCauseCheck = null; - } - } while (rootCauseCheck != null); - return rootCause; + /* + * Work through the root causes using specific methods for well known types + * and getCause() for the rest. Stop when the next rootCause is null or + * an exception is found that has itself as its own rootCause. + */ + private static final Throwable findRootCause(Throwable theException, + Throwable theRootCause) { + + Throwable deeperRootCause = null; + + if (theRootCause == null || theRootCause == theException) { + deeperRootCause = theException; + } else if (theRootCause instanceof ServletException) { + deeperRootCause = ((ServletException) theRootCause).getRootCause(); + } else if (theRootCause instanceof JspException) { + deeperRootCause = ((JspException) theRootCause).getRootCause(); + } else if (theRootCause instanceof SQLException) { + deeperRootCause = ((SQLException) theRootCause).getNextException(); + } else { + deeperRootCause = theRootCause.getCause(); + } + + return deeperRootCause; } Modified: tomcat/container/tc5.5.x/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/webapps/docs/changelog.xml?view=diff&rev=498049&r1=498048&r2=498049 ============================================================================== --- tomcat/container/tc5.5.x/webapps/docs/changelog.xml (original) +++ tomcat/container/tc5.5.x/webapps/docs/changelog.xml Fri Jan 19 18:47:25 2007 @@ -79,7 +79,8 @@ </fix> <fix> <bug>39088</bug>: Prevent infinte loops when an exception is thrown - that returns itself for getRootCause(). (markt) + that returns itself for getRootCause(). Based on a patch by Wouter + Zelle. (markt) </fix> <fix> <bug>39436</bug>: Correct MIME type for SVG. (markt) --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]