Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-1833

NullPointerException using fileName property of RollingFile Appender with DirectWriteRolloverStrategy

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.8.1
    • Fix Version/s: 2.9.0
    • Component/s: None
    • Labels:
      None
    • Environment:

      Windows 7 64-bit JDK 8

      Description

      When using a RollingFileAppender with a DirectWriteRolloverStrategy if the fileName property of the appender is set, rollover fails with a NullPointerException. If the fileName attribute is not present logging works as intended.

      Configuration that produces this error:

      log4j2.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <Configuration status="warn" name="MyApp" packages="">
          <Properties>
              <Property name="baseDir">C:/logs</Property>
          </Properties>
          <Appenders>
              <RollingFile name="RollingFile" fileName="${baseDir}/app.log"
                           filePattern="${baseDir}/app-%d{yyyy-MM-dd'T'HH_mm_ss}.log">
                  <PatternLayout pattern="%d %p %c{1.} [%t] %m%n" />
                  <TimeBasedTriggeringPolicy interval="10"/>
                  <DirectWriteRolloverStrategy>
                      <Delete basePath="${baseDir}">
                          <IfFileName glob="app-*.log" />
                          <IfAccumulatedFileCount exceeds="10" />
                      </Delete>
                  </DirectWriteRolloverStrategy>
              </RollingFile>
          </Appenders>
          <Loggers>
              <Root level="trace">
                  <AppenderRef ref="RollingFile"/>
              </Root>
          </Loggers>
      </Configuration>
      

      Stack Trace:

      2017-03-02 13:38:52,023 main ERROR An exception occurred processing Appender RollingFile java.lang.NullPointerException: activeFileName
      	at java.util.Objects.requireNonNull(Objects.java:228)
      	at org.apache.logging.log4j.core.appender.rolling.RolloverDescriptionImpl.<init>(RolloverDescriptionImpl.java:60)
      	at org.apache.logging.log4j.core.appender.rolling.DirectWriteRolloverStrategy.rollover(DirectWriteRolloverStrategy.java:194)
      	at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.rollover(RollingFileManager.java:362)
      	at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.rollover(RollingFileManager.java:278)
      	at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.checkRollover(RollingFileManager.java:218)
      	at org.apache.logging.log4j.core.appender.RollingFileAppender.append(RollingFileAppender.java:267)
      	at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:156)
      	at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:129)
      	at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:120)
      	at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:84)
      	at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:448)
      	at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:433)
      	at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:417)
      	at org.apache.logging.log4j.core.config.LoggerConfig.logParent(LoggerConfig.java:439)
      	at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:434)
      	at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:417)
      	at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:403)
      	at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:63)
      	at org.apache.logging.log4j.core.Logger.logMessage(Logger.java:146)
      	at org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2091)
      	at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:1993)
      	at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1852)
      	at org.apache.logging.slf4j.Log4jLogger.error(Log4jLogger.java:299)
      

        Activity

        Hide
        albernhagen Andrew Bernhagen added a comment -

        I am also encountering this error.

        Show
        albernhagen Andrew Bernhagen added a comment - I am also encountering this error.
        Hide
        ralph.goers@dslextreme.com Ralph Goers added a comment -

        While this error needs to be fixed, the result of the fix is going to be that an error will be logged during configuration and the Appender will be disabled. The "real" fix is to not specify a fileName attribute as is documented.

        Show
        ralph.goers@dslextreme.com Ralph Goers added a comment - While this error needs to be fixed, the result of the fix is going to be that an error will be logged during configuration and the Appender will be disabled. The "real" fix is to not specify a fileName attribute as is documented.
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 915e681e5e2bc3ad3f2eaeff9d10d38a07ef277c in logging-log4j2's branch refs/heads/master from Ralph Goers
        [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=915e681 ]

        LOG4J2-1833 - Log an error message if a file name is specified with the DirectWriteRolloverStrategy

        Show
        jira-bot ASF subversion and git services added a comment - Commit 915e681e5e2bc3ad3f2eaeff9d10d38a07ef277c in logging-log4j2's branch refs/heads/master from Ralph Goers [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=915e681 ] LOG4J2-1833 - Log an error message if a file name is specified with the DirectWriteRolloverStrategy
        Hide
        ralph.goers@dslextreme.com Ralph Goers added a comment -

        The fix has been applied. Please verify and close.

        Show
        ralph.goers@dslextreme.com Ralph Goers added a comment - The fix has been applied. Please verify and close.
        Hide
        AHuck Austin Huck added a comment -

        Verified, thank you!

        Show
        AHuck Austin Huck added a comment - Verified, thank you!

          People

          • Assignee:
            ralph.goers@dslextreme.com Ralph Goers
            Reporter:
            AHuck Austin Huck
          • Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development