ASF Bugzilla – Attachment 20709 Details for
Bug 40212
NullPointerException in getLogger when called from ShutdownHook
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch to fix the same NPE in Category.java
npe-category.patch (text/plain), 12.34 KB, created by
Aaron Digulla
on 2007-08-25 08:54:45 UTC
(
hide
)
Description:
Patch to fix the same NPE in Category.java
Filename:
MIME Type:
Creator:
Aaron Digulla
Created:
2007-08-25 08:54:45 UTC
Size:
12.34 KB
patch
obsolete
>Index: tests/src/java/org/apache/log4j/CategoryTest.java >=================================================================== >--- tests/src/java/org/apache/log4j/CategoryTest.java (revision 569686) >+++ tests/src/java/org/apache/log4j/CategoryTest.java (working copy) >@@ -96,7 +96,7 @@ > */ > public MockCategory(final String name) { > super(name); >- repository = new Hierarchy(this); >+ setHierarchy(new Hierarchy(this)); > } > > /** >Index: tests/src/java/org/apache/log4j/customLogger/XLogger.java >=================================================================== >--- tests/src/java/org/apache/log4j/customLogger/XLogger.java (revision 569686) >+++ tests/src/java/org/apache/log4j/customLogger/XLogger.java (working copy) >@@ -72,7 +72,7 @@ > XLevel#LETHAL}. */ > public > void lethal(String message, Throwable t) { >- if(repository.isDisabled(XLevel.LETHAL_INT)) >+ if(getLoggerRepository().isDisabled(XLevel.LETHAL_INT)) > return; > if(XLevel.LETHAL.isGreaterOrEqual(this.getEffectiveLevel())) > forcedLog(FQCN, XLevel.LETHAL, message, t); >@@ -83,7 +83,7 @@ > XLevel#LETHAL}. */ > public > void lethal(String message) { >- if(repository.isDisabled(XLevel.LETHAL_INT)) >+ if(getLoggerRepository().isDisabled(XLevel.LETHAL_INT)) > return; > if(XLevel.LETHAL.isGreaterOrEqual(this.getEffectiveLevel())) > forcedLog(FQCN, XLevel.LETHAL, message, null); >@@ -117,7 +117,7 @@ > */ > public > void trace(String message, Throwable t) { >- if(repository.isDisabled(XLevel.TRACE_INT)) >+ if(getLoggerRepository().isDisabled(XLevel.TRACE_INT)) > return; > if(XLevel.TRACE.isGreaterOrEqual(this.getEffectiveLevel())) > forcedLog(FQCN, XLevel.TRACE, message, t); >@@ -128,7 +128,7 @@ > */ > public > void trace(String message) { >- if(repository.isDisabled(XLevel.TRACE_INT)) >+ if(getLoggerRepository().isDisabled(XLevel.TRACE_INT)) > return; > if(XLevel.TRACE.isGreaterOrEqual(this.getEffectiveLevel())) > forcedLog(FQCN, XLevel.TRACE, message, null); >Index: src/main/java/org/apache/log4j/spi/NOPLogger.java >=================================================================== >--- src/main/java/org/apache/log4j/spi/NOPLogger.java (revision 569686) >+++ src/main/java/org/apache/log4j/spi/NOPLogger.java (working copy) >@@ -37,7 +37,7 @@ > */ > public NOPLogger(NOPLoggerRepository repo, final String name) { > super(name); >- this.repository = repo; >+ setHierarchy(repo); > this.level = Level.OFF; > this.parent = this; > } >Index: src/main/java/org/apache/log4j/Category.java >=================================================================== >--- src/main/java/org/apache/log4j/Category.java (revision 569686) >+++ src/main/java/org/apache/log4j/Category.java (working copy) >@@ -35,8 +35,10 @@ > import org.apache.log4j.spi.LoggingEvent; > import org.apache.log4j.spi.LoggerRepository; > import org.apache.log4j.spi.HierarchyEventListener; >+import org.apache.log4j.spi.NOPLoggerRepository; > import org.apache.log4j.helpers.NullEnumeration; > import org.apache.log4j.helpers.AppenderAttachableImpl; >+import org.apache.log4j.helpers.LogLog; > > import java.util.Enumeration; > import java.util.MissingResourceException; >@@ -120,7 +122,9 @@ > protected ResourceBundle resourceBundle; > > // Categories need to know what Hierarchy they are in >- protected LoggerRepository repository; >+ private LoggerRepository repository; >+ // Remember who set the repository to null >+ private Exception nulledBy; > > > AppenderAttachableImpl aai; >@@ -162,7 +166,7 @@ > aai = new AppenderAttachableImpl(); > } > aai.addAppender(newAppender); >- repository.fireAddAppenderEvent(this, newAppender); >+ getLoggerRepository().fireAddAppenderEvent(this, newAppender); > } > > /** >@@ -212,7 +216,7 @@ > } > > if(writes == 0) { >- repository.emitNoAppenderWarning(this); >+ getLoggerRepository().emitNoAppenderWarning(this); > } > } > >@@ -254,7 +258,7 @@ > @param message the message object to log. */ > public > void debug(Object message) { >- if(repository.isDisabled(Level.DEBUG_INT)) >+ if(getLoggerRepository().isDisabled(Level.DEBUG_INT)) > return; > if(Level.DEBUG.isGreaterOrEqual(this.getEffectiveLevel())) { > forcedLog(FQCN, Level.DEBUG, message, null); >@@ -273,7 +277,7 @@ > @param t the exception to log, including its stack trace. */ > public > void debug(Object message, Throwable t) { >- if(repository.isDisabled(Level.DEBUG_INT)) >+ if(getLoggerRepository().isDisabled(Level.DEBUG_INT)) > return; > if(Level.DEBUG.isGreaterOrEqual(this.getEffectiveLevel())) > forcedLog(FQCN, Level.DEBUG, message, t); >@@ -299,7 +303,7 @@ > @param message the message object to log */ > public > void error(Object message) { >- if(repository.isDisabled(Level.ERROR_INT)) >+ if(getLoggerRepository().isDisabled(Level.ERROR_INT)) > return; > if(Level.ERROR.isGreaterOrEqual(this.getEffectiveLevel())) > forcedLog(FQCN, Level.ERROR, message, null); >@@ -316,7 +320,7 @@ > @param t the exception to log, including its stack trace. */ > public > void error(Object message, Throwable t) { >- if(repository.isDisabled(Level.ERROR_INT)) >+ if(getLoggerRepository().isDisabled(Level.ERROR_INT)) > return; > if(Level.ERROR.isGreaterOrEqual(this.getEffectiveLevel())) > forcedLog(FQCN, Level.ERROR, message, t); >@@ -359,7 +363,7 @@ > @param message the message object to log */ > public > void fatal(Object message) { >- if(repository.isDisabled(Level.FATAL_INT)) >+ if(getLoggerRepository().isDisabled(Level.FATAL_INT)) > return; > if(Level.FATAL.isGreaterOrEqual(this.getEffectiveLevel())) > forcedLog(FQCN, Level.FATAL, message, null); >@@ -376,7 +380,7 @@ > @param t the exception to log, including its stack trace. */ > public > void fatal(Object message, Throwable t) { >- if(repository.isDisabled(Level.FATAL_INT)) >+ if(getLoggerRepository().isDisabled(Level.FATAL_INT)) > return; > if(Level.FATAL.isGreaterOrEqual(this.getEffectiveLevel())) > forcedLog(FQCN, Level.FATAL, message, t); >@@ -499,7 +503,7 @@ > @since 1.1 */ > public > LoggerRepository getHierarchy() { >- return repository; >+ return getLoggerRepository(); > } > > /** >@@ -509,6 +513,10 @@ > @since 1.2 */ > public > LoggerRepository getLoggerRepository() { >+ if (repository == null) { >+ LogLog.error("Category.repository was null likely due to error in class reloading or someone setting it to null. Using NOPLoggerRepository.", nulledBy); >+ repository = new NOPLoggerRepository(); >+ } > return repository; > } > >@@ -660,7 +668,7 @@ > @param message the message object to log */ > public > void info(Object message) { >- if(repository.isDisabled(Level.INFO_INT)) >+ if(getLoggerRepository().isDisabled(Level.INFO_INT)) > return; > if(Level.INFO.isGreaterOrEqual(this.getEffectiveLevel())) > forcedLog(FQCN, Level.INFO, message, null); >@@ -677,7 +685,7 @@ > @param t the exception to log, including its stack trace. */ > public > void info(Object message, Throwable t) { >- if(repository.isDisabled(Level.INFO_INT)) >+ if(getLoggerRepository().isDisabled(Level.INFO_INT)) > return; > if(Level.INFO.isGreaterOrEqual(this.getEffectiveLevel())) > forcedLog(FQCN, Level.INFO, message, t); >@@ -731,7 +739,7 @@ > * */ > public > boolean isDebugEnabled() { >- if(repository.isDisabled( Level.DEBUG_INT)) >+ if(getLoggerRepository().isDisabled( Level.DEBUG_INT)) > return false; > return Level.DEBUG.isGreaterOrEqual(this.getEffectiveLevel()); > } >@@ -746,7 +754,7 @@ > */ > public > boolean isEnabledFor(Priority level) { >- if(repository.isDisabled(level.level)) >+ if(getLoggerRepository().isDisabled(level.level)) > return false; > return level.isGreaterOrEqual(this.getEffectiveLevel()); > } >@@ -760,7 +768,7 @@ > */ > public > boolean isInfoEnabled() { >- if(repository.isDisabled(Level.INFO_INT)) >+ if(getLoggerRepository().isDisabled(Level.INFO_INT)) > return false; > return Level.INFO.isGreaterOrEqual(this.getEffectiveLevel()); > } >@@ -776,7 +784,7 @@ > @since 0.8.4 */ > public > void l7dlog(Priority priority, String key, Throwable t) { >- if(repository.isDisabled(priority.level)) { >+ if(getLoggerRepository().isDisabled(priority.level)) { > return; > } > if(priority.isGreaterOrEqual(this.getEffectiveLevel())) { >@@ -800,7 +808,7 @@ > */ > public > void l7dlog(Priority priority, String key, Object[] params, Throwable t) { >- if(repository.isDisabled(priority.level)) { >+ if(getLoggerRepository().isDisabled(priority.level)) { > return; > } > if(priority.isGreaterOrEqual(this.getEffectiveLevel())) { >@@ -819,7 +827,7 @@ > */ > public > void log(Priority priority, Object message, Throwable t) { >- if(repository.isDisabled(priority.level)) { >+ if(getLoggerRepository().isDisabled(priority.level)) { > return; > } > if(priority.isGreaterOrEqual(this.getEffectiveLevel())) >@@ -831,7 +839,7 @@ > */ > public > void log(Priority priority, Object message) { >- if(repository.isDisabled(priority.level)) { >+ if(getLoggerRepository().isDisabled(priority.level)) { > return; > } > if(priority.isGreaterOrEqual(this.getEffectiveLevel())) >@@ -849,7 +857,7 @@ > @param t The throwable of the logging request, may be null. */ > public > void log(String callerFQCN, Priority level, Object message, Throwable t) { >- if(repository.isDisabled(level.level)) { >+ if(getLoggerRepository().isDisabled(level.level)) { > return; > } > if(level.isGreaterOrEqual(this.getEffectiveLevel())) { >@@ -942,8 +950,13 @@ > /** > Only the Hiearchy class can set the hiearchy of a > category. Default package access is MANDATORY here. */ >+ protected // TODO Must be protected for NOPLogger and CategoryTest. > final > void setHierarchy(LoggerRepository repository) { >+ nulledBy = null; >+ if (repository == null) { >+ nulledBy = new Exception("Repository was nulled here."); >+ } > this.repository = repository; > } > >@@ -1036,7 +1049,7 @@ > @param message the message object to log. */ > public > void warn(Object message) { >- if(repository.isDisabled( Level.WARN_INT)) >+ if(getLoggerRepository().isDisabled( Level.WARN_INT)) > return; > > if(Level.WARN.isGreaterOrEqual(this.getEffectiveLevel())) >@@ -1054,7 +1067,7 @@ > @param t the exception to log, including its stack trace. */ > public > void warn(Object message, Throwable t) { >- if(repository.isDisabled(Level.WARN_INT)) >+ if(getLoggerRepository().isDisabled(Level.WARN_INT)) > return; > if(Level.WARN.isGreaterOrEqual(this.getEffectiveLevel())) > forcedLog(FQCN, Level.WARN, message, t); >Index: src/main/java/org/apache/log4j/Logger.java >=================================================================== >--- src/main/java/org/apache/log4j/Logger.java (revision 569686) >+++ src/main/java/org/apache/log4j/Logger.java (working copy) >@@ -62,7 +62,7 @@ > @param message the message object to log. */ > //public > //void fine(Object message) { >- // if(repository.isDisabled(Level.DEBUG_INT)) >+ // if(getLoggerRepository().isDisabled(Level.DEBUG_INT)) > // return; > // if(Level.DEBUG.isGreaterOrEqual(this.getChainedLevel())) { > // forcedLog(FQCN, Level.DEBUG, message, null); >@@ -81,7 +81,7 @@ > @param t the exception to log, including its stack trace. */ > //public > //void fine(Object message, Throwable t) { >- // if(repository.isDisabled(Level.DEBUG_INT)) >+ // if(getLoggerRepository().isDisabled(Level.DEBUG_INT)) > // return; > // if(Level.DEBUG.isGreaterOrEqual(this.getChainedLevel())) > // forcedLog(FQCN, Level.FINE, message, t); >@@ -164,7 +164,7 @@ > * @since 1.2.12 > */ > public void trace(Object message) { >- if (repository.isDisabled(Level.TRACE_INT)) { >+ if (getLoggerRepository().isDisabled(Level.TRACE_INT)) { > return; > } > >@@ -186,7 +186,7 @@ > * @since 1.2.12 > */ > public void trace(Object message, Throwable t) { >- if (repository.isDisabled(Level.TRACE_INT)) { >+ if (getLoggerRepository().isDisabled(Level.TRACE_INT)) { > return; > } > >@@ -203,7 +203,7 @@ > * TRACE, <code>false</code> otherwise. > */ > public boolean isTraceEnabled() { >- if (repository.isDisabled(Level.TRACE_INT)) { >+ if (getLoggerRepository().isDisabled(Level.TRACE_INT)) { > return false; > } >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 40212
: 20709 |
20710