commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1449064 - in /commons/proper/logging/trunk/src/main/java/org/apache/commons/logging: LogFactory.java impl/LogFactoryImpl.java
Date Fri, 22 Feb 2013 14:49:22 GMT
Author: tn
Date: Fri Feb 22 14:49:22 2013
New Revision: 1449064

URL: http://svn.apache.org/r1449064
Log:
[LOGGING-144] Do not swallow certain Errors anymore, like ThreadDeath and VirtualMachineError.

Modified:
    commons/proper/logging/trunk/src/main/java/org/apache/commons/logging/LogFactory.java
    commons/proper/logging/trunk/src/main/java/org/apache/commons/logging/impl/LogFactoryImpl.java

Modified: commons/proper/logging/trunk/src/main/java/org/apache/commons/logging/LogFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/logging/trunk/src/main/java/org/apache/commons/logging/LogFactory.java?rev=1449064&r1=1449063&r2=1449064&view=diff
==============================================================================
--- commons/proper/logging/trunk/src/main/java/org/apache/commons/logging/LogFactory.java
(original)
+++ commons/proper/logging/trunk/src/main/java/org/apache/commons/logging/LogFactory.java
Fri Feb 22 14:49:22 2013
@@ -333,6 +333,8 @@ public abstract class LogFactory {
             Class implementationClass = Class.forName(storeImplementationClass);
             result = (Hashtable) implementationClass.newInstance();
         } catch (Throwable t) {
+            handleThrowable(t); // may re-throw t
+
             // ignore
             if (!WEAK_HASHTABLE_CLASSNAME.equals(storeImplementationClass)) {
                 // if the user's trying to set up a custom implementation, give a clue
@@ -363,6 +365,28 @@ public abstract class LogFactory {
     }
 
     /**
+     * Checks whether the supplied Throwable is one that needs to be
+     * re-thrown and ignores all others.
+     *
+     * The following errors are re-thrown:
+     * <ul>
+     *   <li>ThreadDeath</li>
+     *   <li>VirtualMachineError</li>
+     * </ul>
+     *
+     * @param t the Throwable to check
+     */
+    protected static void handleThrowable(Throwable t) {
+        if (t instanceof ThreadDeath) {
+            throw (ThreadDeath) t;
+        }
+        if (t instanceof VirtualMachineError) {
+            throw (VirtualMachineError) t;
+        }
+        // All other instances of Throwable will be silently ignored
+    }
+
+    /**
      * Construct (if necessary) and return a <code>LogFactory</code>
      * instance, using the following ordered lookup procedure to determine
      * the name of the implementation class to be loaded.
@@ -1337,7 +1361,7 @@ public abstract class LogFactory {
                         if (stream != null) {
                             try {
                                 stream.close();
-                            } catch (Throwable t) {
+                            } catch (IOException e) {
                                 // ignore exception; this should not happen
                                 if (isDiagnosticsEnabled()) {
                                     logDiagnostic("Unable to close stream for URL " + url);

Modified: commons/proper/logging/trunk/src/main/java/org/apache/commons/logging/impl/LogFactoryImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/logging/trunk/src/main/java/org/apache/commons/logging/impl/LogFactoryImpl.java?rev=1449064&r1=1449063&r2=1449064&view=diff
==============================================================================
--- commons/proper/logging/trunk/src/main/java/org/apache/commons/logging/impl/LogFactoryImpl.java
(original)
+++ commons/proper/logging/trunk/src/main/java/org/apache/commons/logging/impl/LogFactoryImpl.java
Fri Feb 22 14:49:22 2013
@@ -425,7 +425,7 @@ public class LogFactoryImpl extends LogF
             } else {
                 classLoaderName = objectId(classLoader);
             }
-        } catch(SecurityException e) {
+        } catch (SecurityException e) {
             classLoaderName = "UNKNOWN";
         }
         diagnosticPrefix = "[LogFactoryImpl@" + System.identityHashCode(this) + " from "
+ classLoaderName + "] ";
@@ -565,6 +565,7 @@ public class LogFactoryImpl extends LogF
             Throwable c = e.getTargetException();
             throw new LogConfigurationException(c == null ? e : c);
         } catch (Throwable t) {
+            handleThrowable(t); // may re-throw t
             // A problem occurred invoking the Constructor or Method
             // previously discovered
             throw new LogConfigurationException(t);
@@ -635,7 +636,7 @@ public class LogFactoryImpl extends LogF
                             return cl.getParent();
                         }
                     });
-        } catch(SecurityException ex) {
+        } catch (SecurityException ex) {
             logDiagnostic("[SECURITY] Unable to obtain parent classloader");
             return null;
         }
@@ -668,7 +669,7 @@ public class LogFactoryImpl extends LogF
                 }
                 return true;
             }
-        } catch(LogConfigurationException e) {
+        } catch (LogConfigurationException e) {
             if (isDiagnosticsEnabled()) {
                 logDiagnostic("Logging system '" + name + "' is available but not useable.");
             }
@@ -1067,11 +1068,12 @@ public class LogFactoryImpl extends LogF
                               "' is unable to initialize itself when loaded via classloader
" + objectId(currentCL) +
                               ": " + msg.trim());
                 break;
-            } catch(LogConfigurationException e) {
+            } catch (LogConfigurationException e) {
                 // call to handleFlawedHierarchy above must have thrown
                 // a LogConfigurationException, so just throw it on
                 throw e;
-            } catch(Throwable t) {
+            } catch (Throwable t) {
+                handleThrowable(t); // may re-throw t
                 // handleFlawedDiscovery will determine whether this is a fatal
                 // problem or not. If it is fatal, then a LogConfigurationException
                 // will be thrown.
@@ -1097,6 +1099,7 @@ public class LogFactoryImpl extends LogF
                 this.logMethod = logAdapterClass.getMethod("setLogFactory", logMethodSignature);
                 logDiagnostic("Found method setLogFactory(LogFactory) in '" + logAdapterClassName
+ "'");
             } catch (Throwable t) {
+                handleThrowable(t); // may re-throw t
                 this.logMethod = null;
                 logDiagnostic("[INFO] '" + logAdapterClassName + "' from classloader " +
objectId(currentCL) +
                               " does not declare optional method " + "setLogFactory(LogFactory)");
@@ -1337,6 +1340,7 @@ public class LogFactoryImpl extends LogF
                                   objectId(badClassLoader) + ". It is bound to a Log interface
which is not" +
                                   " the one loaded from classloader " + objectId(logInterfaceClassLoader));
                 } catch (Throwable t) {
+                    handleThrowable(t); // may re-throw t
                     logDiagnostic("Error while trying to output diagnostics about" + " bad
class '" + badClass + "'");
                 }
             }



Mime
View raw message