You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Remko Popma (JIRA)" <ji...@apache.org> on 2013/03/16 08:32:12 UTC

[jira] [Commented] (LOG4J2-177) ERROR StatusLogger An exception occurred processing Appender udpsocket java.lang.NullPointerException

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

Remko Popma commented on LOG4J2-177:
------------------------------------

Looks like the SocketAppender defaults to immediateFlush=true, so the flush() method is called on every log event.
At the end of the flush, the data byte array is set to null.
If you have multiple threads logging, and the flush() method is called twice in a row, this error will occur.

The fix is to add a null check to the flush() method implementation.

change DatagramOutputStream.flush (line 93)
    if (this.ds != null && this.address != null) {
to
    if (this.data != null && this.ds != null && this.address != null) {

                
> ERROR StatusLogger An exception occurred processing Appender udpsocket java.lang.NullPointerException
> -----------------------------------------------------------------------------------------------------
>
>                 Key: LOG4J2-177
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-177
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Appenders
>    Affects Versions: 2.0-beta4
>            Reporter: Aaron Daniels
>
> This seems to be a race condition of some kind. Two threads are exiting at almost exactly the same time, and both print a message as they exit. This exception happens every 3 or 4 times the code is run, so it's easily reproducible.
> ERROR StatusLogger An exception occurred processing Appender udpsocket java.lang.NullPointerException
> 	at org.apache.logging.log4j.core.net.DatagramOutputStream.flush(DatagramOutputStream.java:93)
> 	at org.apache.logging.log4j.core.appender.OutputStreamManager.flush(OutputStreamManager.java:146)
> 	at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.append(AbstractOutputStreamAppender.java:117)
> 	at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:102)
> 	at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:335)
> 	at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:316)
> 	at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:281)
> 	at org.apache.logging.log4j.core.Logger.log(Logger.java:108)
> 	at org.apache.logging.log4j.spi.AbstractLogger.trace(AbstractLogger.java:250)
> 	at com.galmont.automation.framework.gui.handlers.RunCycleHandler$2.run(RunCycleHandler.java:128)
> 	at java.lang.Thread.run(Unknown Source)
> My configuration file:
> <?xml version="1.0" encoding="UTF-8"?>
> <configuration status="OFF">
> 	
> 	<appenders>
> 		<Console name="console" target="SYSTEM_OUT">
> 			<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
> 		</Console>
> 		<Socket name="udpsocket" host="localhost" port="90" protocol="UDP">
> 			<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
> 		</Socket>
> 		<RollingFile name="RollingFile" fileName="logs/app.log" filePattern="logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz">
> 			<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
> 			<Policies>
> 				<SizeBasedTriggeringPolicy size="20 MB" />
> 			</Policies>
> 		</RollingFile>
> 	</appenders>
> 	
> 	<loggers>
> 		<root level="trace">
> 			<appender-ref ref="console" />
> 			<appender-ref ref="udpsocket" />
> 			<appender-ref ref="RollingFile" />
> 		</root>
> 	</loggers>
> 	
> </configuration>

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org