Skip to content

Commit d0f108a

Browse files
authored
Avoid instanceof if redacted exceptions are active (#3553)
* Avoid instanceof if redacted exceptions are active * Added changelog * Fix test
1 parent 815b213 commit d0f108a

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

CHANGELOG.asciidoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ Use subheadings with the "=====" level for adding notes for unreleased changes:
3131
3232
=== Unreleased
3333
34+
[float]
35+
===== Bug fixes
36+
* Avoid another case where we might touch application exceptions for `safe_exceptions` - {pull}3553[#3553]
37+
38+
3439
[[release-notes-1.x]]
3540
=== Java Agent version 1.x
3641

apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ElasticApmTracer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ public Service createService(String ephemeralId) {
10021002
@Override
10031003
@Nullable
10041004
public Throwable redactExceptionIfRequired(@Nullable Throwable original) {
1005-
if (original != null && coreConfiguration.isRedactExceptions() && !(original instanceof RedactedException)) {
1005+
if (original != null && coreConfiguration.isRedactExceptions()) {
10061006
return new RedactedException();
10071007
}
10081008
return original;

apm-agent-core/src/test/java/org/example/stacktrace/ErrorCaptureTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,16 @@ void testExceptionRedaction() {
117117
Throwable redacted = tracer.redactExceptionIfRequired(exception);
118118
assertThat(redacted).isInstanceOf(RedactedException.class);
119119

120-
assertThat(tracer.redactExceptionIfRequired(redacted)).isSameAs(redacted);
120+
// double redaction means no instanceof check
121+
assertThat(tracer.redactExceptionIfRequired(redacted)).isNotSameAs(redacted);
121122

122123
ErrorCapture errorCapture = tracer.captureException(exception, tracer.currentContext(), null);
123124
assertThat(errorCapture).isNotNull();
124125
assertThat(errorCapture.getException()).isInstanceOf(RedactedException.class);
125126

126127
ErrorCapture alreadyRedacted = tracer.captureException(redacted, tracer.currentContext(), null);
127128
assertThat(alreadyRedacted).isNotNull();
128-
assertThat(alreadyRedacted.getException()).isSameAs(redacted);
129+
assertThat(alreadyRedacted.getException()).isNotSameAs(redacted);
129130
}
130131

131132

0 commit comments

Comments
 (0)