Lukas Vogel created LOG4J2-1916:
-----------------------------------

             Summary: Nullpointer with DirectWriteRolloverStrategy
                 Key: LOG4J2-1916
                 URL: https://issues.apache.org/jira/browse/LOG4J2-1916
             Project: Log4j 2
          Issue Type: Bug
          Components: Appenders
    Affects Versions: 2.8.2
         Environment: Unix
            Reporter: Lukas Vogel


h3.Steps to reproduce:
Rolling config:
{code:xml}
<RollingFile name="Service" 
        fileName="foo.log" 
        filePattern="foo-%d{yyyy-MM-dd}-%i.log">
        <PatternLayout charset="UTF-8">
                <pattern>%m%n</pattern>
        </PatternLayout>
            <Policies>
                <TimeBasedTriggeringPolicy />
                <SizeBasedTriggeringPolicy size="1KB"/>
        </Policies>
        <DirectWriteRolloverStrategy />
</RollingFile>
{code}

-Start program with given Log config. 
-Log something (>1KB).
-Log something again -> NPE

h3.Stacktrace:
{code}
2017-05-19 10:20:52,752 http-nio-9081-exec-2 ERROR An exception occurred 
processing Appender Service 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.appender.routing.RoutingAppender.append(RoutingAppender.java:227)
        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.appender.routing.RoutingAppender.append(RoutingAppender.java:227)
        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.info(Log4jLogger.java:179)
{code}

h2.Possible Fix
I think on line 184 in DirectWirteRolloverStrategy the assignment should be:
 final String sourceName = getCurrentFileName(manager);
instead of using the field currentFileName.




--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to