ramanathan1504 commented on issue #4143:
URL: 
https://github.com/apache/logging-log4j2/issues/4143#issuecomment-4680608596

   Hi @Zschimmer ,
   
   Thank you for providing the detailed reproduction case. After investigating 
this alongside the Log4j maintainers, we have confirmed that this 
`NullPointerException` is the second half of a larger "Identity Malfunction" we 
have been tracking.
   
   #### **The Technical Context**
   The root cause of your NPE is identical to the one reported in [Issue 
#3933](https://github.com/apache/logging-log4j2/issues/3933) 
(**ArrayIndexOutOfBoundsException**). 
   
   1. **The Core Flaw:** The internal `ThrowableStackTraceRenderer` was using a 
standard `HashMap` to cache exception metadata. This relies on logical equality 
(`.equals()`) and `hashCode()`.
   2. **The Resulting Symptoms:** 
      * **In #3933 (AIOOBE):** Different exceptions with colliding `equals()` 
methods caused the renderer to use the wrong metadata for different objects.
      * **In #4143 (NPE):** In environments like **ScalaTest** or **Apache 
Spark**, exceptions often have a mutating `hashCode()`. When the hash changes 
between the caching and rendering phases, the `HashMap.get()` call fails and 
returns `null`, causing the crash you observed.
   
   #### **Relationship to #3955**
   While the recently released version **2.26.0** included changes from 
[#3955](https://github.com/apache/logging-log4j2/issues/3955) that mitigated 
some symptoms of the AIOOBE, it did not resolve the underlying identity 
malfunction. Your report of the NPE proved that the standard `HashMap` approach 
remained fundamentally unstable for complex exception chains.
   
   #### **The Definitive Fix**
   We have now migrated the metadata caching logic to use an 
**`IdentityHashMap`**. By switching to reference equality (`==`) and 
`System.identityHashCode()`, the renderer is now resilient to:
   * Custom `equals()` implementations.
   * Mutating `hashCode()` values.
   * Reused exception instances in a single chain.
   
   #### **Status & Verification**
   The fix has been merged into the **`2.x`** branch. 
   
   **I invite you to test the current state of the `2.x` branch in your Scala 
environment.** If you can confirm that the NPE is resolved and the stack traces 
render correctly, I will close this issue as resolved. This fix is scheduled 
for the next release (**2.27.0**).
   
   Thank you for helping us make Log4j more robust for the Scala and Spark 
ecosystems!


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