-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix stack trace rendering for exceptions with identity malfunction #4133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+104
−15
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
53e2b76
Fix circular reference detection for exceptions with colliding equals…
ramanathan1504 c9c4173
Add changelog entry for circular reference detection fix with collidi…
ramanathan1504 c65c142
Add changelog entry for circular reference detection fix with collidi…
ramanathan1504 377a429
Add test for ThrowableProxy serialization with colliding equals/hashC…
ramanathan1504 8ddbc1b
Refactor ThrowableProxy serialization test to use modern Java I/O cla…
ramanathan1504 6388cac
Merge remote-tracking branch 'origin/2.x' into issue-3933
vy ee66e87
Use `TestFriendlyException` to exercise the malfunction
vy 3cb4438
Update changelog
vy 1fd45a7
Improve comments
vy 2b93e18
Remove redundant change
vy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
...re-test/src/main/java/org/apache/logging/log4j/core/test/impl/ThrowableCollisionTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to you under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.logging.log4j.core.test.impl; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import java.util.Objects; | ||
| import org.apache.logging.log4j.core.impl.ThrowableProxy; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class ThrowableCollisionTest { | ||
|
|
||
| static class CollidingException extends RuntimeException { | ||
| public CollidingException(String message, Throwable cause) { | ||
| super(message, cause); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object obj) { | ||
| return obj instanceof CollidingException | ||
| && Objects.equals(getMessage(), ((CollidingException) obj).getMessage()); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hashCode(getMessage()); | ||
| } | ||
| } | ||
|
|
||
| static class CyclicException extends RuntimeException { | ||
| private Throwable customCause; | ||
|
|
||
| public CyclicException(String message) { | ||
| super(message); | ||
| } | ||
|
|
||
| public void setCustomCause(Throwable cause) { | ||
| this.customCause = cause; | ||
| } | ||
|
|
||
| @Override | ||
| public Throwable getCause() { | ||
| return customCause; | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testCollisionDoesNotTriggerCircularReference() { | ||
| Throwable inner = new CollidingException("collision", null); | ||
| Throwable outer = new CollidingException("collision", inner); | ||
|
|
||
| assertDoesNotThrow(() -> { | ||
| ThrowableProxy proxy = new ThrowableProxy(outer); | ||
| String trace = proxy.getExtendedStackTraceAsString(); | ||
|
|
||
| assertFalse( | ||
| trace.contains("CIRCULAR REFERENCE"), | ||
| "Should not mark a non-cyclic colliding exception chain as circular!"); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| public void testTrueCircularReferenceIsStillHandledSafely() { | ||
| CyclicException ex1 = new CyclicException("Cycle Exception 1"); | ||
| CyclicException ex2 = new CyclicException("Cycle Exception 2"); | ||
|
|
||
| ex1.setCustomCause(ex2); | ||
| ex2.setCustomCause(ex1); | ||
|
|
||
| assertDoesNotThrow(() -> { | ||
| ThrowableProxy proxy = new ThrowableProxy(ex1); | ||
| String trace = proxy.getExtendedStackTraceAsString(); | ||
|
|
||
| assertTrue( | ||
| trace.contains("CIRCULAR REFERENCE"), | ||
| "Should successfully detect and flag a genuine cyclic reference!"); | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/changelog/.2.x.x/fix-circular-reference-detection-for-exceptions-with-colliding.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <entry xmlns="https://logging.apache.org/xml/ns" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation=" | ||
| https://logging.apache.org/xml/ns | ||
| https://logging.apache.org/xml/ns/log4j-changelog-0.xsd" | ||
| type="changed"> | ||
| <issue id="3933" link="https://github.com/apache/logging-log4j2/issues/3933"/> | ||
| <issue id="4133" link="https://github.com/apache/logging-log4j2/pull/4133"/> | ||
| <description format="asciidoc"> | ||
| Fix `circular reference` detection for exceptions with `colliding` equals/hashCode implementations | ||
| </description> | ||
| </entry> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.