From b74547399e261701b9e8c5bdebd930df77897d2a Mon Sep 17 00:00:00 2001 From: markt Date: Sun, 28 Jan 2007 17:28:36 +0000 Subject: [PATCH] Update JspException to align with the JSP 2.1 spec. Update root cause finding to take advantage of being able to use getCause git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@500843 13f79535-47bb-0310-9956-ffa450edef68 --- java/javax/servlet/jsp/JspException.java | 50 ++++++++++------------ java/org/apache/catalina/core/StandardWrapper.java | 19 +------- .../apache/catalina/valves/ErrorReportValve.java | 20 +-------- 3 files changed, 25 insertions(+), 64 deletions(-) diff --git a/java/javax/servlet/jsp/JspException.java b/java/javax/servlet/jsp/JspException.java index 39d98be97..b99887439 100644 --- a/java/javax/servlet/jsp/JspException.java +++ b/java/javax/servlet/jsp/JspException.java @@ -48,55 +48,51 @@ public class JspException extends Exception { /** - * Constructs a new JSP exception when the JSP - * needs to throw an exception and include a message - * about the "root cause" exception that interfered with its - * normal operation, including a description message. - * + * Constructs a new JSPException with the specified detail + * message and cause. The cause is saved for later retrieval by the + * java.lang.Throwable.getCause() and {@link #getRootCause()} + * methods. + * + * @see java.lang.Exception.Exception(String, Throwable) * * @param message a String containing the text of the * exception message * - * @param rootCause the Throwable exception that - * interfered with the servlet's normal operation, - * making this servlet exception necessary + * @param cause the Throwable exception that + * interfered with the JSP's normal operation, + * making this JSP exception necessary */ - public JspException(String message, Throwable rootCause) { - super(message); - this.rootCause = rootCause; + public JspException(String message, Throwable cause) { + super(message, cause); } /** - * Constructs a new JSP exception when the JSP - * needs to throw an exception and include a message - * about the "root cause" exception that interfered with its - * normal operation. The exception's message is based on the localized - * message of the underlying exception. - * - *

This method calls the getLocalizedMessage method - * on the Throwable exception to get a localized exception - * message. When subclassing JspException, - * this method can be overridden to create an exception message - * designed for a specific locale. + * Constructs a new JSPException with the specified cause. + * The cause is saved for later retrieval by the + * java.lang.Throwable.getCause() and {@link #getRootCause()} + * methods. + * + * @see java.lang.Exception.Exception(Throwable) * - * @param rootCause the Throwable exception that + * @param cause the Throwable exception that * interfered with the JSP's normal operation, making * the JSP exception necessary */ - public JspException(Throwable rootCause) { - super(rootCause.getLocalizedMessage()); - this.rootCause = rootCause; + public JspException(Throwable cause) { + super(cause); } /** + * @deprecated As of JSP 2.1, replaced by + * java.lang.Throwable.getCause() + * * Returns the exception that caused this JSP exception. * * @return the Throwable that caused this JSP exception - * */ public Throwable getRootCause() { diff --git a/java/org/apache/catalina/core/StandardWrapper.java b/java/org/apache/catalina/core/StandardWrapper.java index c090a6237..159da6b44 100644 --- a/java/org/apache/catalina/core/StandardWrapper.java +++ b/java/org/apache/catalina/core/StandardWrapper.java @@ -62,7 +62,6 @@ import org.apache.catalina.Wrapper; 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.tomcat.util.modeler.Registry; @@ -295,18 +294,6 @@ public class StandardWrapper protected static Properties restrictedServlets = null; - private static Class jspExceptionClazz; - - static { - try { - jspExceptionClazz = Class.forName("javax.servlet.jsp.JspException"); - } catch (ClassNotFoundException e) { - // Expected if jsp-api not on classpath, eg when embedding - jspExceptionClazz = null; - } - } - - // ------------------------------------------------------------- Properties @@ -709,11 +696,7 @@ public class StandardWrapper return theException; } - if (jspExceptionClazz!=null && - jspExceptionClazz.isAssignableFrom(theRootCause.getClass())) { - deeperRootCause = (Throwable)IntrospectionUtils.getProperty( - theRootCause, "rootCause"); - } else if (theRootCause instanceof SQLException) { + if (theRootCause instanceof SQLException) { deeperRootCause = ((SQLException) theRootCause).getNextException(); } if (deeperRootCause == null) { diff --git a/java/org/apache/catalina/valves/ErrorReportValve.java b/java/org/apache/catalina/valves/ErrorReportValve.java index 479cba368..7560df38d 100644 --- a/java/org/apache/catalina/valves/ErrorReportValve.java +++ b/java/org/apache/catalina/valves/ErrorReportValve.java @@ -34,7 +34,6 @@ import org.apache.catalina.connector.Response; import org.apache.catalina.util.RequestUtil; import org.apache.catalina.util.ServerInfo; import org.apache.catalina.util.StringManager; -import org.apache.tomcat.util.IntrospectionUtils; /** *

Implementation of a Valve that outputs HTML error pages.

@@ -73,18 +72,6 @@ public class ErrorReportValve StringManager.getManager(Constants.Package); - private static Class jspExceptionClazz; - - static { - try { - jspExceptionClazz = Class.forName("javax.servlet.jsp.JspException"); - } catch (ClassNotFoundException e) { - // Expected if jsp-api not on classpath, eg when embedding - jspExceptionClazz = null; - } - } - - // ------------------------------------------------------------- Properties @@ -241,12 +228,7 @@ public class ErrorReportValve sb.append("

"); // In case root cause is somehow heavily nested try { - if (jspExceptionClazz!=null && - jspExceptionClazz.isAssignableFrom( - rootCause.getClass())) { - nestedRootCause = (Throwable)IntrospectionUtils. - getProperty(rootCause, "rootCause"); - } else if (rootCause instanceof SQLException) { + if (rootCause instanceof SQLException) { nestedRootCause = ((SQLException) rootCause). getNextException(); } -- 2.11.0