ashitpatel opened a new issue, #4512:
URL: https://github.com/apache/logging-log4j2/issues/4512

   ## Description
   
   In the log4j-1.2 bridge, `Category.callAppenders` reads `aai` under 
`synchronized (c)`:
   
   ```java
   synchronized (c) {
       if (c.aai != null) {
           writes += c.aai.appendLoopOnAppenders(event);
       }
       ...
   }
   ```
   
   but `Category.removeAllAppenders` is not synchronized: it iterates the 
appenders, calls `aai.removeAllAppenders()`, fires remove events, and only then 
sets `aai = null`. If another thread's `callAppenders` passes the null check in 
between, it dereferences the nulled `aai` and throws NullPointerException. The 
field is also not volatile, so the window is wider than the race itself.
   
   Trigger: one thread logging through a 1.2-bridge Category in a loop while 
another thread calls `removeAllAppenders()` on it (e.g. a reconfiguration 
path). I have not executed this — reporting from code reading plus a model of 
the interleaving, so please treat the report with appropriate skepticism; a 
sketch of the reproducer is below.
   
   ## Configuration
   
   **Version:** 2.x branch HEAD (verified 2026-11-21)
   
   **Operating system:** N/A (code reading; any OS)
   
   **JDK:** N/A (any; would reproduce with e.g. OpenJDK 21+ and a two-thread 
JUnit test)
   
   ## Logs
   
   None (no execution; the NPE site is `Category.java:249`, 
`c.aai.appendLoopOnAppenders(event)` after `aai` is nulled at line 584).
   
   ## Reproduction
   
   Unrun sketch (two threads sharing one Category: one calling a logging method 
in a tight loop, one calling `removeAllAppenders()` repeatedly; expect 
intermittent NPE from `callAppenders`). I can turn this into a real JUnit test 
in the repo's style if the diagnosis looks right — just say the word.
   
   Possible direction: synchronize `removeAllAppenders` (and ideally 
`removeAppender`, same shape) on the Category, matching `callAppenders`.


-- 
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