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

NullPointerException when closing never used RollingRandomAccessFileAppender

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.10.0, 2.11.1
    • 3.0.0, 2.11.2
    • Appenders
    • None

    Description

      If a RollingRandomAccessFileAppender is configured using the DirectWriteRolloverStrategy and there is no log event which is passed to this appender there will be a NullPointerException when the configuration is stoped.

      java.lang.NullPointerException
      at org.apache.logging.log4j.core.appender.rolling.RollingRandomAccessFileManager.closeOutputStream(RollingRandomAccessFileManager.java:168)
      at org.apache.logging.log4j.core.appender.OutputStreamManager.releaseSub(OutputStreamManager.java:136)
      at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.releaseSub(RollingFileManager.java:266)
      at org.apache.logging.log4j.core.appender.AbstractManager.stop(AbstractManager.java:86)
      at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.stop(AbstractOutputStreamAppender.java:142)
      at org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender.stop(RollingRandomAccessFileAppender.java:223)
      at org.apache.logging.log4j.core.config.AbstractConfiguration.stop(AbstractConfiguration.java:360)
      at org.apache.logging.log4j.core.AbstractLifeCycle.stop(AbstractLifeCycle.java:136)
      at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:552)
      at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:619)
      at org.apache.logging.log4j.core.LoggerContext.setConfigLocation(LoggerContext.java:605)
      at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.locateContext(ClassLoaderContextSelector.java:157)
      at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:70)
      at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:228)
      at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:158)
      at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:131)
      at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:101)
      at org.apache.logging.log4j.junit.LoggerContextRule$1.evaluate(LoggerContextRule.java:120)
      at org.junit.rules.RunRules.evaluate(RunRules.java:20)
      [...]
      

      To reproduce the issue a config may be created wich does not use this appender:

      <Configuration status="WARN">
       <Appenders>
        <Console name="Console" target="SYSTEM_OUT"></Console>
        <RollingRandomAccessFile name="DatedLogFile" filePattern="log.%d{yyyyMMdd}" immediateFlush="false">
         <TimeBasedTriggeringPolicy />
         <DirectWriteRolloverStrategy />
        </RollingRandomAccessFile>
       </Appenders>
       <Loggers>
        <Root level="warn">
         <AppenderRef ref="Console" />
        </Root>
       </Loggers>
      </Configuration>
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              jonasr Jonas Rutishauser
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: