ramanathan1504 commented on code in PR #4133:
URL: https://github.com/apache/logging-log4j2/pull/4133#discussion_r3395710861
##########
log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ThrowableStackTraceRenderer.java:
##########
@@ -64,7 +67,11 @@ public final void renderThrowable(
@SuppressWarnings("unchecked")
C createContext(final Throwable throwable) {
- final Map<Throwable, Context.Metadata> metadataByThrowable =
Context.Metadata.ofThrowable(throwable);
+ // `IdentityHashMap` is needed to deal with custom `equals()` and
`hashCode()` implementations causing
+ // collisions
+ final Map<Throwable, Context.Metadata> metadataByThrowable = new
IdentityHashMap<>();
+ Context.Metadata.populateMetadata(
+ metadataByThrowable, Collections.newSetFromMap(new
IdentityHashMap<>()), null, throwable);
Review Comment:
Hi @vy,
I have verified the changes. I ran a targeted reproduction test for #4143
(using a Throwable with a mutating hashCode) and confirmed that the refactored
Context.Metadata.ofThrowable(throwable) successfully prevents the
NullPointerException. It also correctly handles the equals() collision from
#3933.
The refactoring is much cleaner, and since the GitHub CI is now green across
all platforms, I am confident this resolves both issues.
Thank you for the cleanup and the refactor!"
--
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]