Skip to content

Commit

Permalink
Use AssertionError(String, Throwable) instead of supplying the caus…
Browse files Browse the repository at this point in the history
…e 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
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed May 29, 2024
1 parent eea7ac0 commit 7a1c72f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ final class AssertionErrorWithFacts extends AssertionError implements ErrorWithF

AssertionErrorWithFacts(
ImmutableList<String> messages, ImmutableList<Fact> facts, @Nullable Throwable cause) {
super(makeMessage(messages, facts));
super(makeMessage(messages, facts), cause);
this.facts = checkNotNull(facts);

initCause(cause);
}

@Override
Expand Down
4 changes: 1 addition & 3 deletions core/src/main/java/com/google/common/truth/Truth.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 7a1c72f

Please sign in to comment.