You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2014/08/25 23:42:40 UTC
svn commit: r1620464 -
/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
Author: ggregory
Date: Mon Aug 25 21:42:40 2014
New Revision: 1620464
URL: http://svn.apache.org/r1620464
Log:
Fix NPEs in new shutdown hook code. I'm not sure if this is the right fix, but it's a fix. It's not clear to me that the new shotdown hook code will be in 2.1 based on the back and forth in JIRA and ML.
Modified:
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java?rev=1620464&r1=1620463&r2=1620464&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java Mon Aug 25 21:42:40 2014
@@ -196,20 +196,22 @@ public class LoggerContext extends Abstr
ShutdownRegistrationStrategy.SHUTDOWN_REGISTRATION_STRATEGY);
if (shutdownStrategyClassName != null) {
try {
- shutdownRegistrationStrategy =
- Loader.newCheckedInstanceOf(shutdownStrategyClassName, ShutdownRegistrationStrategy.class);
+ shutdownRegistrationStrategy = Loader.newCheckedInstanceOf(shutdownStrategyClassName,
+ ShutdownRegistrationStrategy.class);
} catch (final Exception e) {
- LOGGER.error(SHUTDOWN_HOOK_MARKER, "There was an error loading the ShutdownRegistrationStrategy [{}]. " +
- "Falling back to DefaultShutdownRegistrationStrategy.", shutdownStrategyClassName, e);
+ LOGGER.error(SHUTDOWN_HOOK_MARKER,
+ "There was an error loading the ShutdownRegistrationStrategy [{}]. "
+ + "Falling back to DefaultShutdownRegistrationStrategy.",
+ shutdownStrategyClassName, e);
shutdownRegistrationStrategy = new DefaultShutdownRegistrationStrategy();
}
- }
- try {
- shutdownRegistrationStrategy.registerShutdownHook(hook);
- } catch (final IllegalStateException ise) {
- LOGGER.fatal(SHUTDOWN_HOOK_MARKER, "Unable to register shutdown hook because JVM is shutting down.");
- } catch (final SecurityException se) {
- LOGGER.error(SHUTDOWN_HOOK_MARKER, "Unable to register shutdown hook due to security restrictions");
+ try {
+ shutdownRegistrationStrategy.registerShutdownHook(hook);
+ } catch (final IllegalStateException ise) {
+ LOGGER.fatal(SHUTDOWN_HOOK_MARKER, "Unable to register shutdown hook because JVM is shutting down.");
+ } catch (final SecurityException se) {
+ LOGGER.error(SHUTDOWN_HOOK_MARKER, "Unable to register shutdown hook due to security restrictions");
+ }
}
}
}
@@ -245,8 +247,9 @@ public class LoggerContext extends Abstr
}
private void tearDownShutdownHook() {
- if (shutdownThread != null && shutdownThread.get() != null) {
- shutdownRegistrationStrategy.unregisterShutdownHook(shutdownThread.get());
+ Thread thread = shutdownThread.get();
+ if (shutdownRegistrationStrategy != null && shutdownThread != null && thread != null) {
+ shutdownRegistrationStrategy.unregisterShutdownHook(thread);
LOGGER.debug(SHUTDOWN_HOOK_MARKER, "Enqueue shutdown hook for garbage collection.");
shutdownThread.enqueue();
}