[ 
https://issues.apache.org/jira/browse/LOG4J2-2027?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16153110#comment-16153110
 ] 

Ralph Goers commented on LOG4J2-2027:
-------------------------------------

Prior to the addition of createOnDemand writing the header used the 
OutputStream that was passed in to the constructor. My first thought is to 
wonder why we are now calling getOutputStream in that location as we shouldn't 
even be trying to write the header of the provided OutputStream is null. But I 
am not sure of all the other changes that were made to when create on demand 
was added so I am unsure what would break if the check for header != null was 
changed to header != null && os != null (and probably the call to 
getOutputStream right afterwards was changed back to use the os variable.  I 
would have to add a test that fails in this case and then try that and see.

> File appenders fail to configure when using a header with createOnDemand=true
> -----------------------------------------------------------------------------
>
>                 Key: LOG4J2-2027
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2027
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Appenders
>    Affects Versions: 2.8.2
>            Reporter: Paul Burrowes
>            Priority: Minor
>
> FileManager and RollingFileManager are not completely initialised when 
> OutputStreamManager.<init> tries to create a stream to log the header. This 
> only occurs when append=false, createOnDemand=true and the appender has a 
> layout with a header.
> The key to the problem is that if createOnDemand=false the FileManagerFactory 
> will create the FileOutputStream before constructing the FileManager 
> (FileManager.java:422, RollingFIleManager.java:635). 
> I suspect that the DirectWriteStrategy may be vulnerable to this too.
> RandomAccessFileManager is not affected by this because it does not support 
> createOnDemand.
> For example
> {code}
> <RollingFile fileName="test.log" filePattern="test.log.%i" append="false" 
> createOnDemand="true">
>     <PatternLayout pattern="%d %m" header="Test header"/>
> </RollingFile>
> {code}
> Stack trace of the failure showing that OutputStreamManager is trying to 
> write the header in an incompletely constructed FileManager.
> {code}
> 2017-09-01 17:09:36.016+1200 ERROR   [log4j.status] <GroupRMI-thread-1> {} 
> Unable to inject fields into builder class for plugin type class 
> org.apache.logging.log4j.core.appender.RollingFileAppender, element 
> RollingFile.
> java.lang.NullPointerException: name can't be null
>         at java.io.FilePermission.init(FilePermission.java:191)
>         at java.io.FilePermission.<init>(FilePermission.java:277)
>         at java.lang.SecurityManager.checkWrite(SecurityManager.java:979)
>         at java.io.FileOutputStream.<init>(FileOutputStream.java:200)
>         at java.io.FileOutputStream.<init>(FileOutputStream.java:133)
>         at 
> org.apache.logging.log4j.core.appender.FileManager.createOutputStream(FileManager.java:120)
>         at 
> org.apache.logging.log4j.core.appender.OutputStreamManager.getOutputStream(OutputStreamManager.java:166)
>         at 
> org.apache.logging.log4j.core.appender.OutputStreamManager.<init>(OutputStreamManager.java:95)
>         at 
> org.apache.logging.log4j.core.appender.FileManager.<init>(FileManager.java:84)
>         at 
> org.apache.logging.log4j.core.appender.rolling.RollingFileManager.<init>(RollingFileManager.java:111)
>         at 
> org.apache.logging.log4j.core.appender.rolling.RollingFileManager$RollingFileManagerFactory.createManager(RollingFileManager.java:593)
>         at 
> org.apache.logging.log4j.core.appender.rolling.RollingFileManager$RollingFileManagerFactory.createManager(RollingFileManager.java:554)
>         at 
> org.apache.logging.log4j.core.appender.AbstractManager.getManager(AbstractManager.java:112)
>         at 
> org.apache.logging.log4j.core.appender.OutputStreamManager.getManager(OutputStreamManager.java:114)
>         at 
> org.apache.logging.log4j.core.appender.rolling.RollingFileManager.getFileManager(RollingFileManager.java:155)
>         at 
> org.apache.logging.log4j.core.appender.RollingFileAppender$Builder.build(RollingFileAppender.java:131)
>         at 
> org.apache.logging.log4j.core.appender.RollingFileAppender$Builder.build(RollingFileAppender.java:60)
>         at 
> org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:122)
>         at 
> org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:952)
>         at 
> org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:892)
>         at 
> org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:884)
>         at 
> org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:508)
>         at 
> org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:232)
>         at 
> org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:244)
>         at 
> org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:545)
>         at 
> org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:261)
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to