Zschimmer commented on issue #3929:
URL: 
https://github.com/apache/logging-log4j2/issues/3929#issuecomment-4249816946

   The NullPointerException reproducible without using threads. It appears when 
calling addSuppressed some microseconds after the exception has been logged. 
Then the line is not written to the log file.
   
   This inhibits us to use the TLS vulnerability fix #4002.
   
   Example in Scala, Log4jNullPointerExceptionTest.sc:
   ```//> using dep org.apache.logging.log4j:log4j-api:2.25.4
   //> using dep org.apache.logging.log4j:log4j-core:2.25.4
   //> using dep org.apache.logging.log4j:log4j-slf4j2-impl:2.25.4
   //> using dep com.lmax:disruptor:3.4.4
   //> using dep org.slf4j:slf4j-api:2.0.17
   
   import java.lang.System.setProperty
   import org.slf4j.LoggerFactory
   
   // Log4j 2.25 logs NullPointerException to stderr without aborting the test
   setProperty("log4j2.configurationFile", "./log4j2.xml")
   setProperty("log4j2.contextSelector", 
"org.apache.logging.log4j.core.async.AsyncLoggerContextSelector")
   val logger = LoggerFactory.getLogger("Log4jNullPointerExceptionTest")
   val suppressed = new Exception("Suppressed")
   
   (1 to 10_000).foreach: i =>
     val exception = new Exception("Log4jNullPointerExceptionTest")
     val nanoseconds = i * 10 % 1_000_000
     logger.debug(s"${nanoseconds / 1000.0}µs", exception)
     Thread.sleep(0, nanoseconds)
     // Adding a suppressed exception while the AsyncLogger is still logging 
the exception may
     // cause a NullPointerException (visible in stderr output)
     exception.addSuppressed(suppressed)
   ```
   
   log4j2.xml:
   ```
   <?xml version="1.0" encoding="UTF-8"?>
   <configuration status="WARN">
     <appenders>
       <randomAccessFile name="file" fileName="test.log" append="false" 
immediateFlush="false">
         <patternLayout
           pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} %level %logger - %message%n"
           charset="UTF-8"/>
       </randomAccessFile>
     </appenders>
   
     <loggers>
       <root level="trace">
         <appenderRef level="trace" ref="file"/>
       </root>
     </loggers>
   </configuration>
   ```
   
   Run with 
   `scala Log4jNullPointerExceptionTest.sc`
   
   On my computer, three times a NullPointerException is logged to stderr after 
8µs.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to