Partial fix for https://issues.apache.org/bugzilla/show_bug.cgi?id=48644
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 27 Sep 2010 22:01:45 +0000 (22:01 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 27 Sep 2010 22:01:45 +0000 (22:01 +0000)
Some Throwables must always be re-thrown

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

22 files changed:
java/org/apache/catalina/mbeans/MBeanUtils.java
java/org/apache/catalina/mbeans/ServerLifecycleListener.java
java/org/apache/catalina/realm/JAASRealm.java
java/org/apache/catalina/realm/JDBCRealm.java
java/org/apache/catalina/realm/UserDatabaseRealm.java
java/org/apache/catalina/session/StandardManager.java
java/org/apache/catalina/session/StandardSession.java
java/org/apache/catalina/startup/Bootstrap.java
java/org/apache/catalina/startup/Catalina.java
java/org/apache/catalina/startup/CatalinaProperties.java
java/org/apache/catalina/startup/ContextConfig.java
java/org/apache/catalina/startup/HostConfig.java
java/org/apache/catalina/startup/TldConfig.java
java/org/apache/catalina/startup/Tool.java
java/org/apache/catalina/tribes/membership/McastServiceImpl.java
java/org/apache/catalina/tribes/transport/nio/NioReceiver.java
java/org/apache/catalina/util/CharsetMapper.java
java/org/apache/catalina/util/ServerInfo.java
java/org/apache/catalina/valves/AccessLogValve.java
java/org/apache/catalina/valves/ErrorReportValve.java
java/org/apache/catalina/valves/ExtendedAccessLogValve.java
java/org/apache/catalina/valves/JDBCAccessLogValve.java

index 896e06b..66ee9d4 100644 (file)
@@ -1072,6 +1072,7 @@ public class MBeanUtils {
             try {
                 mserver = Registry.getRegistry(null, null).getMBeanServer();
             } catch (Throwable t) {
+                ExceptionUtils.handleThrowable(t);
                 t.printStackTrace(System.out);
                 System.exit(1);
             }
index ee4e5a2..7ebfa77 100644 (file)
@@ -48,6 +48,7 @@ import org.apache.catalina.deploy.ContextEnvironment;
 import org.apache.catalina.deploy.ContextResource;
 import org.apache.catalina.deploy.ContextResourceLink;
 import org.apache.catalina.deploy.NamingResources;
+import org.apache.jasper.util.ExceptionUtils;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 
@@ -150,9 +151,8 @@ public class ServerLifecycleListener
                 log.error("createMBeans: MBeanException", e);
 
             } catch (Throwable t) {
-
+                ExceptionUtils.handleThrowable(t);
                 log.error("createMBeans: Throwable", t);
-
             }
 
              /*
@@ -180,9 +180,8 @@ public class ServerLifecycleListener
                 log.error("destroyMBeans: MBeanException", e);
 
             } catch (Throwable t) {
-
+                ExceptionUtils.handleThrowable(t);
                 log.error("destroyMBeans: Throwable", t);
-
             }
             // FIXME: RMI adaptor should be stopped; however, this is
             // undocumented in MX4J, and reports exist in the MX4J bug DB that
@@ -925,6 +924,7 @@ public class ServerLifecycleListener
                 e = t;
             log.error("processContainerAddChild: MBeanException", e);
         } catch (Throwable t) {
+            ExceptionUtils.handleThrowable(t);
             log.error("processContainerAddChild: Throwable", t);
         }
 
@@ -1060,6 +1060,7 @@ public class ServerLifecycleListener
                 e = t;
             log.error("processContainerRemoveChild: MBeanException", e);
         } catch (Throwable t) {
+            ExceptionUtils.handleThrowable(t);
             log.error("processContainerRemoveChild: Throwable", t);
         }
 
index 60f985e..1b38fe8 100644 (file)
@@ -36,6 +36,7 @@ import org.apache.catalina.Container;
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.authenticator.Constants;
 import org.apache.catalina.util.LifecycleBase;
+import org.apache.jasper.util.ExceptionUtils;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 
@@ -390,6 +391,7 @@ public class JAASRealm
         try {
             loginContext = new LoginContext(appName, callbackHandler);
         } catch (Throwable e) {
+            ExceptionUtils.handleThrowable(e);
             log.error(sm.getString("jaasRealm.unexpectedError"), e);
             return (null);
         } finally {
@@ -427,6 +429,7 @@ public class JAASRealm
             log.warn(sm.getString("jaasRealm.loginException", username), e);
             return (null);
         } catch (Throwable e) {
+            ExceptionUtils.handleThrowable(e);
             log.error(sm.getString("jaasRealm.unexpectedError"), e);
             return (null);
         }
index 5921569..d88a93f 100644 (file)
@@ -698,6 +698,7 @@ public class JDBCRealm
                 Class<?> clazz = Class.forName(driverName);
                 driver = (Driver) clazz.newInstance();
             } catch (Throwable e) {
+                ExceptionUtils.handleThrowable(e);
                 throw new SQLException(e.getMessage());
             }
         }
index 9de514c..ecde2a7 100644 (file)
@@ -33,6 +33,7 @@ import org.apache.catalina.User;
 import org.apache.catalina.UserDatabase;
 import org.apache.catalina.core.StandardServer;
 import org.apache.catalina.util.LifecycleBase;
+import org.apache.jasper.util.ExceptionUtils;
 
 
 /**
@@ -249,6 +250,7 @@ public class UserDatabaseRealm
                 ((StandardServer)getServer()).getGlobalNamingContext();
             database = (UserDatabase) context.lookup(resourceName);
         } catch (Throwable e) {
+            ExceptionUtils.handleThrowable(e);
             containerLog.error(sm.getString("userDatabaseRealm.lookup",
                                             resourceName),
                                e);
index 93e2858..13dff8d 100644 (file)
@@ -466,6 +466,7 @@ public class StandardManager extends ManagerBase {
         try {
             load();
         } catch (Throwable t) {
+            ExceptionUtils.handleThrowable(t);
             log.error(sm.getString("standardManager.managerLoad"), t);
         }
 
@@ -492,6 +493,7 @@ public class StandardManager extends ManagerBase {
         try {
             unload();
         } catch (Throwable t) {
+            ExceptionUtils.handleThrowable(t);
             log.error(sm.getString("standardManager.managerUnload"), t);
         }
 
index 9e3564d..f0c8dea 100644 (file)
@@ -57,6 +57,7 @@ import org.apache.catalina.core.StandardContext;
 import org.apache.catalina.realm.GenericPrincipal;
 import org.apache.catalina.security.SecurityUtil;
 import org.apache.catalina.util.Enumerator;
+import org.apache.jasper.util.ExceptionUtils;
 import org.apache.tomcat.util.res.StringManager;
 
 /**
@@ -405,6 +406,7 @@ public class StandardSession
                                        "afterSessionCreated",
                                        listener);
                 } catch (Throwable t) {
+                    ExceptionUtils.handleThrowable(t);
                     try {
                         fireContainerEvent(context,
                                            "afterSessionCreated",
@@ -776,6 +778,7 @@ public class StandardSession
                                                "afterSessionDestroyed",
                                                listener);
                         } catch (Throwable t) {
+                            ExceptionUtils.handleThrowable(t);
                             try {
                                 fireContainerEvent(context,
                                                    "afterSessionDestroyed",
@@ -877,6 +880,7 @@ public class StandardSession
                     ((HttpSessionActivationListener)attribute)
                         .sessionWillPassivate(event);
                 } catch (Throwable t) {
+                    ExceptionUtils.handleThrowable(t);
                     manager.getContainer().getLogger().error
                         (sm.getString("standardSession.attributeEvent"), t);
                 }
@@ -912,6 +916,7 @@ public class StandardSession
                     ((HttpSessionActivationListener)attribute)
                         .sessionDidActivate(event);
                 } catch (Throwable t) {
+                    ExceptionUtils.handleThrowable(t);
                     manager.getContainer().getLogger().error
                         (sm.getString("standardSession.attributeEvent"), t);
                 }
@@ -1423,6 +1428,7 @@ public class StandardSession
                 ((HttpSessionBindingListener) unbound).valueUnbound
                     (new HttpSessionBindingEvent(getSession(), name));
             } catch (Throwable t) {
+                ExceptionUtils.handleThrowable(t);
                 manager.getContainer().getLogger().error
                     (sm.getString("standardSession.bindingEvent"), t);
             }
@@ -1467,6 +1473,7 @@ public class StandardSession
                                        listener);
                 }
             } catch (Throwable t) {
+                ExceptionUtils.handleThrowable(t);
                 try {
                     if (unbound != null) {
                         fireContainerEvent(context,
@@ -1764,6 +1771,7 @@ public class StandardSession
                                    "afterSessionAttributeRemoved",
                                    listener);
             } catch (Throwable t) {
+                ExceptionUtils.handleThrowable(t);
                 try {
                     fireContainerEvent(context,
                                        "afterSessionAttributeRemoved",
index c50a5c0..f017aee 100644 (file)
@@ -33,6 +33,7 @@ import javax.management.ObjectName;
 
 import org.apache.catalina.Globals;
 import org.apache.catalina.security.SecurityClassLoad;
+import org.apache.jasper.util.ExceptionUtils;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 
@@ -98,6 +99,7 @@ public final class Bootstrap {
             catalinaLoader = createClassLoader("server", commonLoader);
             sharedLoader = createClassLoader("shared", commonLoader);
         } catch (Throwable t) {
+            ExceptionUtils.handleThrowable(t);
             log.error("Class loader creation threw exception", t);
             System.exit(1);
         }
@@ -391,6 +393,7 @@ public final class Bootstrap {
             try {
                 bootstrap.init();
             } catch (Throwable t) {
+                ExceptionUtils.handleThrowable(t);
                 t.printStackTrace();
                 return;
             }
@@ -420,6 +423,7 @@ public final class Bootstrap {
                 log.warn("Bootstrap: command \"" + command + "\" does not exist.");
             }
         } catch (Throwable t) {
+            ExceptionUtils.handleThrowable(t);
             t.printStackTrace();
         }
 
index 50e081e..058fbc3 100644 (file)
@@ -36,6 +36,7 @@ import org.apache.catalina.LifecycleException;
 import org.apache.catalina.Server;
 import org.apache.catalina.core.StandardServer;
 import org.apache.catalina.security.SecurityConfig;
+import org.apache.jasper.util.ExceptionUtils;
 import org.apache.juli.ClassLoaderLogManager;
 import org.apache.tomcat.util.IntrospectionUtils;
 import org.apache.tomcat.util.digester.Digester;
@@ -611,6 +612,7 @@ public class Catalina {
                 }
             }
         } catch (Throwable t) {
+            ExceptionUtils.handleThrowable(t);
             // This will fail on JDK 1.2. Ignoring, as Tomcat can run
             // fine without the shutdown hook.
         }
@@ -643,6 +645,7 @@ public class Catalina {
                 }
             }
         } catch (Throwable t) {
+            ExceptionUtils.handleThrowable(t);
             // This will fail on JDK 1.2. Ignoring, as Tomcat can run
             // fine without the shutdown hook.
         }
@@ -804,6 +807,7 @@ public class Catalina {
                     Catalina.this.stop();
                 }
             } catch (Throwable ex) {
+                ExceptionUtils.handleThrowable(ex);
                 log.error(sm.getString("catalina.shutdownHookFail"), ex);
             } finally {
                 // If JULI is used, shut JULI down *after* the server shuts down
index f59f07e..213f1ad 100644 (file)
@@ -122,6 +122,7 @@ public class CatalinaProperties {
                 properties.load(is);
                 is.close();
             } catch (Throwable t) {
+                handleThrowable(t);
                 error = t;
             }
         }
index f2c9504..342a00d 100644 (file)
@@ -437,6 +437,7 @@ public class ContextConfig
                 Class<?> authenticatorClass = Class.forName(authenticatorName);
                 authenticator = (Valve) authenticatorClass.newInstance();
             } catch (Throwable t) {
+                ExceptionUtils.handleThrowable(t);
                 log.error(sm.getString(
                                     "contextConfig.authenticatorInstantiate",
                                     authenticatorName),
index f1e10da..b30d710 100644 (file)
@@ -678,6 +678,7 @@ public class HostConfig
                 }
             }
         } catch (Throwable t) {
+            ExceptionUtils.handleThrowable(t);
             log.error(sm.getString("hostConfig.deployDescriptor.error",
                                    file), t);
         }
@@ -964,6 +965,7 @@ public class HostConfig
                 addWatchedResources(deployedApp, null, context);
             }
         } catch (Throwable t) {
+            ExceptionUtils.handleThrowable(t);
             log.error(sm.getString("hostConfig.deployWar.error", file), t);
         }
         
@@ -1082,6 +1084,7 @@ public class HostConfig
             }
             addWatchedResources(deployedApp, dir.getAbsolutePath(), context);
         } catch (Throwable t) {
+            ExceptionUtils.handleThrowable(t);
             log.error(sm.getString("hostConfig.deployDir.error", file), t);
         }
 
@@ -1164,12 +1167,14 @@ public class HostConfig
                     try {
                         host.removeChild(context);
                     } catch (Throwable t) {
+                        ExceptionUtils.handleThrowable(t);
                         log.warn(sm.getString
                                  ("hostConfig.context.remove", app.name), t);
                     }
                     try {
                         context.destroy();
                     } catch (Throwable t) {
+                        ExceptionUtils.handleThrowable(t);
                         log.warn(sm.getString
                                  ("hostConfig.context.destroy", app.name), t);
                     }
@@ -1220,12 +1225,14 @@ public class HostConfig
                 try {
                     host.removeChild(context);
                 } catch (Throwable t) {
+                    ExceptionUtils.handleThrowable(t);
                     log.warn(sm.getString
                              ("hostConfig.context.remove", app.name), t);
                 }
                 try {
                     context.destroy();
                 } catch (Throwable t) {
+                    ExceptionUtils.handleThrowable(t);
                     log.warn(sm.getString
                              ("hostConfig.context.destroy", app.name), t);
                 }
@@ -1383,6 +1390,7 @@ public class HostConfig
             try {
                 host.removeChild(host.findChild(apps[i].name));
             } catch (Throwable t) {
+                ExceptionUtils.handleThrowable(t);
                 log.warn(sm.getString
                         ("hostConfig.context.remove", apps[i].name), t);
             }
index 5ee777a..064fbd4 100644 (file)
@@ -437,7 +437,7 @@ public final class TldConfig  implements LifecycleListener {
                             try {
                                 stream.close();
                             } catch (Throwable t) {
-                                // do nothing
+                                ExceptionUtils.handleThrowable(t);
                             }
                         }
                     }
@@ -481,7 +481,7 @@ public final class TldConfig  implements LifecycleListener {
                             try {
                                 stream.close();
                             } catch (Throwable t) {
-                                // do nothing
+                                ExceptionUtils.handleThrowable(t);
                             }
                         }
                     }
@@ -560,7 +560,7 @@ public final class TldConfig  implements LifecycleListener {
                     try {
                         resourceStream.close();
                     } catch (Throwable t) {
-                        // do nothing
+                        ExceptionUtils.handleThrowable(t);
                     }
                 }
             }
index 27a2600..04beff4 100644 (file)
@@ -24,6 +24,7 @@ import java.lang.reflect.Method;
 import java.util.ArrayList;
 
 import org.apache.catalina.Globals;
+import org.apache.jasper.util.ExceptionUtils;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 
@@ -184,6 +185,7 @@ public final class Tool {
                  packed.toArray(new File[0]),
                  null);
         } catch (Throwable t) {
+            ExceptionUtils.handleThrowable(t);
             log.error("Class loader creation threw exception", t);
             System.exit(1);
         }
@@ -197,6 +199,7 @@ public final class Tool {
                 log.debug("Loading application class " + className);
             clazz = classLoader.loadClass(className);
         } catch (Throwable t) {
+            ExceptionUtils.handleThrowable(t);
             log.error("Exception creating instance of " + className, t);
             System.exit(1);
         }
@@ -213,6 +216,7 @@ public final class Tool {
             paramTypes[0] = params.getClass();
             method = clazz.getMethod(methodName, paramTypes);
         } catch (Throwable t) {
+            ExceptionUtils.handleThrowable(t);
             log.error("Exception locating main() method", t);
             System.exit(1);
         }
@@ -225,6 +229,7 @@ public final class Tool {
             paramValues[0] = params;
             method.invoke(null, paramValues);
         } catch (Throwable t) {
+            ExceptionUtils.handleThrowable(t);
             log.error("Exception calling main() method", t);
             System.exit(1);
         }
index 28d1c47..5099e54 100644 (file)
@@ -36,6 +36,7 @@ import org.apache.catalina.tribes.MessageListener;
 import org.apache.catalina.tribes.io.ChannelData;
 import org.apache.catalina.tribes.io.XByteBuffer;
 import org.apache.catalina.tribes.util.ExecutorFactory;
+import org.apache.jasper.util.ExceptionUtils;
 
 /**
  * A <b>membership</b> implementation using simple multicast.
@@ -420,7 +421,8 @@ public class McastServiceImpl
                                 if (data[i]!=null && !member.equals(data[i].getAddress())) {
                                     msgservice.messageReceived(data[i]);
                                 }
-                            }catch (Throwable t) {
+                            } catch (Throwable t) {
+                                ExceptionUtils.handleThrowable(t);
                                 log.error("Unable to receive broadcast message.",t);
                             }
                         }
index f193835..fcd3972 100644 (file)
@@ -37,6 +37,7 @@ import org.apache.catalina.tribes.transport.Constants;
 import org.apache.catalina.tribes.transport.ReceiverBase;
 import org.apache.catalina.tribes.transport.RxTaskPool;
 import org.apache.catalina.tribes.util.StringManager;
+import org.apache.jasper.util.ExceptionUtils;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 
@@ -318,12 +319,8 @@ public class NioReceiver extends ReceiverBase implements Runnable {
             } catch (java.nio.channels.CancelledKeyException nx) {
                 log.warn("Replication client disconnected, error when polling key. Ignoring client.");
             } catch (Throwable x) {
-                try {
-                    log.error("Unable to process request in NioReceiver", x);
-                }catch ( Throwable tx ) {
-                    //in case an out of memory error, will affect the logging framework as well
-                    tx.printStackTrace();
-                }
+                ExceptionUtils.handleThrowable(x);
+                log.error("Unable to process request in NioReceiver", x);
             }
 
         }
index fce0f96..84c4cee 100644 (file)
@@ -22,6 +22,8 @@ import java.io.InputStream;
 import java.util.Locale;
 import java.util.Properties;
 
+import org.apache.jasper.util.ExceptionUtils;
+
 
 
 /**
@@ -75,6 +77,7 @@ public class CharsetMapper {
             map.load(stream);
             stream.close();
         } catch (Throwable t) {
+            ExceptionUtils.handleThrowable(t);
             throw new IllegalArgumentException(t.toString());
         }
     }
index 348a13e..b7f302b 100644 (file)
@@ -22,6 +22,8 @@ package org.apache.catalina.util;
 import java.io.InputStream;
 import java.util.Properties;
 
+import org.apache.jasper.util.ExceptionUtils;
+
 
 /**
  * Simple utility module to make it easy to plug in the server identifier
@@ -64,7 +66,7 @@ public class ServerInfo {
             serverBuilt = props.getProperty("server.built");
             serverNumber = props.getProperty("server.number");
         } catch (Throwable t) {
-            //Ignore
+            ExceptionUtils.handleThrowable(t);
         }
         if (serverInfo == null)
             serverInfo = "Apache Tomcat 7.0.x-dev";
index ea1feac..3e40f2d 100644 (file)
@@ -44,6 +44,7 @@ import org.apache.catalina.connector.Request;
 import org.apache.catalina.connector.Response;
 import org.apache.catalina.util.LifecycleBase;
 import org.apache.coyote.RequestInfo;
+import org.apache.jasper.util.ExceptionUtils;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 import org.apache.tomcat.util.res.StringManager;
@@ -606,6 +607,7 @@ public class AccessLogValve extends ValveBase implements AccessLog {
             try {
                 holder.renameTo(new File(newFileName));
             } catch (Throwable e) {
+                ExceptionUtils.handleThrowable(e);
                 log.error("rotate failed", e);
             }
 
@@ -676,6 +678,7 @@ public class AccessLogValve extends ValveBase implements AccessLog {
                     try {
                         close();
                     } catch (Throwable e) {
+                        ExceptionUtils.handleThrowable(e);
                         log.info("at least this wasn't swallowed", e);
                     }
 
@@ -712,6 +715,7 @@ public class AccessLogValve extends ValveBase implements AccessLog {
         try {
             index = Integer.parseInt(month) - 1;
         } catch (Throwable t) {
+            ExceptionUtils.handleThrowable(t);
             index = 0;  // Can not happen, in theory
         }
         return (months[index]);
@@ -880,6 +884,7 @@ public class AccessLogValve extends ValveBase implements AccessLog {
             try {
                 init = InetAddress.getLocalHost().getHostAddress();
             } catch (Throwable e) {
+                ExceptionUtils.handleThrowable(e);
                 init = "127.0.0.1";
             }
             LOCAL_ADDR_VALUE = init;
index bdb1d3d..fe99839 100644 (file)
@@ -254,6 +254,7 @@ public class ErrorReportValve extends ValveBase {
                 response.setContentType("text/html");
                 response.setCharacterEncoding("utf-8");
             } catch (Throwable t) {
+                ExceptionUtils.handleThrowable(t);
                 if (container.getLogger().isDebugEnabled())
                     container.getLogger().debug("status.setContentType", t);
             }
index 54a41f6..e0e2c37 100644 (file)
@@ -36,6 +36,7 @@ import javax.servlet.http.HttpSession;
 import org.apache.catalina.connector.Request;
 import org.apache.catalina.connector.Response;
 import org.apache.catalina.util.ServerInfo;
+import org.apache.jasper.util.ExceptionUtils;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 
@@ -180,6 +181,7 @@ public class ExtendedAccessLogValve extends AccessLogValve {
             if ("".equals(svalue))
                 return "-";
         } catch (Throwable e) {
+            ExceptionUtils.handleThrowable(e);
             /* Log error */
             return "-";
         }
@@ -612,6 +614,7 @@ public class ExtendedAccessLogValve extends AccessLogValve {
                         try {
                             value = InetAddress.getLocalHost().getHostName();
                         } catch (Throwable e) {
+                            ExceptionUtils.handleThrowable(e);
                             value = "localhost";
                         }
                         buf.append(value);
index c5643c8..72c04ed 100644 (file)
@@ -539,6 +539,7 @@ public final class JDBCAccessLogValve extends ValveBase implements AccessLog {
                 Class<?> clazz = Class.forName(driverName);
                 driver = (Driver) clazz.newInstance();
             } catch (Throwable e) {
+                ExceptionUtils.handleThrowable(e);
                 throw new SQLException(e.getMessage());
             }
         }