[LOGGING-144] Do not swallow certain Errors anymore, like ThreadDeath and VirtualMachineError.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/logging/trunk@1449064 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -333,6 +333,8 @@ public abstract class LogFactory {
|
|||||||
Class implementationClass = Class.forName(storeImplementationClass);
|
Class implementationClass = Class.forName(storeImplementationClass);
|
||||||
result = (Hashtable) implementationClass.newInstance();
|
result = (Hashtable) implementationClass.newInstance();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
|
handleThrowable(t); // may re-throw t
|
||||||
|
|
||||||
// ignore
|
// ignore
|
||||||
if (!WEAK_HASHTABLE_CLASSNAME.equals(storeImplementationClass)) {
|
if (!WEAK_HASHTABLE_CLASSNAME.equals(storeImplementationClass)) {
|
||||||
// if the user's trying to set up a custom implementation, give a clue
|
// if the user's trying to set up a custom implementation, give a clue
|
||||||
@@ -362,6 +364,28 @@ public abstract class LogFactory {
|
|||||||
return src.trim();
|
return src.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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>
|
* Construct (if necessary) and return a <code>LogFactory</code>
|
||||||
* instance, using the following ordered lookup procedure to determine
|
* instance, using the following ordered lookup procedure to determine
|
||||||
@@ -1337,7 +1361,7 @@ public abstract class LogFactory {
|
|||||||
if (stream != null) {
|
if (stream != null) {
|
||||||
try {
|
try {
|
||||||
stream.close();
|
stream.close();
|
||||||
} catch (Throwable t) {
|
} catch (IOException e) {
|
||||||
// ignore exception; this should not happen
|
// ignore exception; this should not happen
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("Unable to close stream for URL " + url);
|
logDiagnostic("Unable to close stream for URL " + url);
|
||||||
|
|||||||
@@ -565,6 +565,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
Throwable c = e.getTargetException();
|
Throwable c = e.getTargetException();
|
||||||
throw new LogConfigurationException(c == null ? e : c);
|
throw new LogConfigurationException(c == null ? e : c);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
|
handleThrowable(t); // may re-throw t
|
||||||
// A problem occurred invoking the Constructor or Method
|
// A problem occurred invoking the Constructor or Method
|
||||||
// previously discovered
|
// previously discovered
|
||||||
throw new LogConfigurationException(t);
|
throw new LogConfigurationException(t);
|
||||||
@@ -1072,6 +1073,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
// a LogConfigurationException, so just throw it on
|
// a LogConfigurationException, so just throw it on
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
|
handleThrowable(t); // may re-throw t
|
||||||
// handleFlawedDiscovery will determine whether this is a fatal
|
// handleFlawedDiscovery will determine whether this is a fatal
|
||||||
// problem or not. If it is fatal, then a LogConfigurationException
|
// problem or not. If it is fatal, then a LogConfigurationException
|
||||||
// will be thrown.
|
// will be thrown.
|
||||||
@@ -1097,6 +1099,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
this.logMethod = logAdapterClass.getMethod("setLogFactory", logMethodSignature);
|
this.logMethod = logAdapterClass.getMethod("setLogFactory", logMethodSignature);
|
||||||
logDiagnostic("Found method setLogFactory(LogFactory) in '" + logAdapterClassName + "'");
|
logDiagnostic("Found method setLogFactory(LogFactory) in '" + logAdapterClassName + "'");
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
|
handleThrowable(t); // may re-throw t
|
||||||
this.logMethod = null;
|
this.logMethod = null;
|
||||||
logDiagnostic("[INFO] '" + logAdapterClassName + "' from classloader " + objectId(currentCL) +
|
logDiagnostic("[INFO] '" + logAdapterClassName + "' from classloader " + objectId(currentCL) +
|
||||||
" does not declare optional method " + "setLogFactory(LogFactory)");
|
" does not declare optional method " + "setLogFactory(LogFactory)");
|
||||||
@@ -1337,6 +1340,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
objectId(badClassLoader) + ". It is bound to a Log interface which is not" +
|
objectId(badClassLoader) + ". It is bound to a Log interface which is not" +
|
||||||
" the one loaded from classloader " + objectId(logInterfaceClassLoader));
|
" the one loaded from classloader " + objectId(logInterfaceClassLoader));
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
|
handleThrowable(t); // may re-throw t
|
||||||
logDiagnostic("Error while trying to output diagnostics about" + " bad class '" + badClass + "'");
|
logDiagnostic("Error while trying to output diagnostics about" + " bad class '" + badClass + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user