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

RollingFileAppender: NPE when using a custom DirectFileRolloverStrategy without fileName

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.12.1
    • Fix Version/s: 2.13.1
    • Component/s: Appenders
    • Labels:
      None

      Description

       

      I have created a custom RolloverStrategy which implements org.apache.logging.log4j.core.appender.rolling.DirectFileRolloverStrategy (but does not extend DirectWriteRolloverStrategy).

      When I try to use this strategy in a RollingFileAppender with a filePattern, but no fileName, log4j writes an exception to the console and does not work:

       

      2020-01-13 17:22:49,024 StartUp-Thread ERROR An exception occurred processing Appender CustomAppender java.lang.NullPointerException
       at java.base/java.io.File.<init>(File.java:276)
       at org.apache.logging.log4j.core.appender.FileManager.createOutputStream(FileManager.java:190)
       at org.apache.logging.log4j.core.appender.OutputStreamManager.getOutputStream(OutputStreamManager.java:166)
       at org.apache.logging.log4j.core.appender.OutputStreamManager.writeToDestination(OutputStreamManager.java:261)
       at org.apache.logging.log4j.core.appender.FileManager.writeToDestination(FileManager.java:272)
       at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.writeToDestination(RollingFileManager.java:244)
       at org.apache.logging.log4j.core.appender.OutputStreamManager.flushBuffer(OutputStreamManager.java:293)
       at org.apache.logging.log4j.core.appender.OutputStreamManager.flush(OutputStreamManager.java:302)
       at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.directEncodeEvent(AbstractOutputStreamAppender.java:199)
       at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.tryAppend(AbstractOutputStreamAppender.java:190)
       at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.append(AbstractOutputStreamAppender.java:181)
       at org.apache.logging.log4j.core.appender.RollingFileAppender.append(RollingFileAppender.java:312)
       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:543)
       at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:502)
       at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:485)
       at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:460)
       at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:82)
       at org.apache.logging.log4j.core.Logger.log(Logger.java:161)
       at org.apache.logging.log4j.spi.AbstractLogger.tryLogMessage(AbstractLogger.java:2198)
       at org.apache.logging.log4j.spi.AbstractLogger.logMessageTrackRecursion(AbstractLogger.java:2152)
       at org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2135)
       at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2011)
       at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1983)
       at org.apache.logging.log4j.spi.AbstractLogger.info(AbstractLogger.java:1320)
       at IconParc.IpionServer.IpionServer.main(IpionServer.java:1154)
      
      

      The reason for this behaviour is that the RollingFileAppender explicitely checks for instances of DirectWriteRolloverStrategy instead of DirectFileRolloverStrategy like its Builder does.

      I opened a PR (https://github.com/apache/logging-log4j2/pull/331) that fixes this behavior.

       

       

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              christophk Christoph Kaser
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: