From 7a1c72f6661b70e215944062d6c13a805f37bcdb Mon Sep 17 00:00:00 2001 From: cpovirk Date: Wed, 29 May 2024 10:38:03 -0700 Subject: [PATCH] Use `AssertionError(String, Throwable)` instead of supplying the cause later. I could have done this as part of cl/609415936 and cl/604677493, but I'd missed that `AssertionError(String, Throwable)` was [added in API Level 19](https://developer.android.com/reference/java/lang/AssertionError#AssertionError(java.lang.String,%20java.lang.Throwable)). (The code in `Platform` in cl/609415936 still needs to use `initCause` because it uses `ComparisonFailure`, which does not expose a `Throwable`-accepting constructor.) RELNOTES=n/a PiperOrigin-RevId: 638335715 --- .../java/com/google/common/truth/AssertionErrorWithFacts.java | 4 +--- core/src/main/java/com/google/common/truth/Truth.java | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/com/google/common/truth/AssertionErrorWithFacts.java b/core/src/main/java/com/google/common/truth/AssertionErrorWithFacts.java index 0da85e78d..ffdc720c6 100644 --- a/core/src/main/java/com/google/common/truth/AssertionErrorWithFacts.java +++ b/core/src/main/java/com/google/common/truth/AssertionErrorWithFacts.java @@ -31,10 +31,8 @@ final class AssertionErrorWithFacts extends AssertionError implements ErrorWithF AssertionErrorWithFacts( ImmutableList messages, ImmutableList facts, @Nullable Throwable cause) { - super(makeMessage(messages, facts)); + super(makeMessage(messages, facts), cause); this.facts = checkNotNull(facts); - - initCause(cause); } @Override diff --git a/core/src/main/java/com/google/common/truth/Truth.java b/core/src/main/java/com/google/common/truth/Truth.java index 0ffd62548..8b16b6c44 100644 --- a/core/src/main/java/com/google/common/truth/Truth.java +++ b/core/src/main/java/com/google/common/truth/Truth.java @@ -355,9 +355,7 @@ public static PathSubject assertThat(@Nullable Path actual) { @SuppressWarnings("OverrideThrowableToString") // We intentionally replace the normal format. static final class SimpleAssertionError extends AssertionError { private SimpleAssertionError(String message, @Nullable Throwable cause) { - super(checkNotNull(message)); - - initCause(cause); + super(checkNotNull(message), cause); } static SimpleAssertionError create(String message, @Nullable Throwable cause) {