Skip to content

Commit

Permalink
Avoid instanceof if redacted exceptions are active (#3553)
Browse files Browse the repository at this point in the history
* Avoid instanceof if redacted exceptions are active

* Added changelog

* Fix test
  • Loading branch information
JonasKunz authored Mar 6, 2024
1 parent 815b213 commit d0f108a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ Use subheadings with the "=====" level for adding notes for unreleased changes:
=== Unreleased
[float]
===== Bug fixes
* Avoid another case where we might touch application exceptions for `safe_exceptions` - {pull}3553[#3553]
[[release-notes-1.x]]
=== Java Agent version 1.x
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ public Service createService(String ephemeralId) {
@Override
@Nullable
public Throwable redactExceptionIfRequired(@Nullable Throwable original) {
if (original != null && coreConfiguration.isRedactExceptions() && !(original instanceof RedactedException)) {
if (original != null && coreConfiguration.isRedactExceptions()) {
return new RedactedException();
}
return original;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,16 @@ void testExceptionRedaction() {
Throwable redacted = tracer.redactExceptionIfRequired(exception);
assertThat(redacted).isInstanceOf(RedactedException.class);

assertThat(tracer.redactExceptionIfRequired(redacted)).isSameAs(redacted);
// double redaction means no instanceof check
assertThat(tracer.redactExceptionIfRequired(redacted)).isNotSameAs(redacted);

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

ErrorCapture alreadyRedacted = tracer.captureException(redacted, tracer.currentContext(), null);
assertThat(alreadyRedacted).isNotNull();
assertThat(alreadyRedacted.getException()).isSameAs(redacted);
assertThat(alreadyRedacted.getException()).isNotSameAs(redacted);
}


Expand Down

0 comments on commit d0f108a

Please sign in to comment.