Bug 31003 - RollingFileAppender, if removed can cause null pointer exceptions
RollingFileAppender, if removed can cause null pointer exceptions
Status: RESOLVED FIXED
Product: Log4j
Classification: Unclassified
Component: Appender
1.2
Other other
: P3 normal
: ---
Assigned To: log4j-dev
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2004-09-01 20:07 UTC by Elias Ross
Modified: 2006-08-01 12:13 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Elias Ross 2004-09-01 20:07:22 UTC
Steps to reproduce:

    Layout layout = new PatternLayout(this.logfileLayout);
    RollingFileAppender rfa = new RollingFileAppender(layout, filename, true);
    Logger.getRootLogger().addAppender(rfa);
    Logger.getRootLogger().removeAllAppenders();
    rfa.rollOver();

Results:

    [junit] java.lang.NullPointerException
    [junit]     at
org.apache.log4j.RollingFileAppender.rollOver(RollingFileAppender.java:112)

Cause:

cw is null:

src/java/org/apache/log4j/RollingFileAppender.java

  public // synchronization not necessary since doAppend is alreasy synched
  void rollOver() {
    File target;
    File file;
                                                                               
                                                                               
    LogLog.debug("rolling over count=" + ((CountingQuietWriter) qw).getCount());
    LogLog.debug("maxBackupIndex="+maxBackupIndex);
                                                                               
                                                                               

Suggestion:

Either do nothing if the appender is closed or throw a better exception.
Comment 1 Curt Arnold 2006-08-01 19:13:47 UTC
Committed rev 427681.