Skip to content

Commit 7a1c72f

Browse files
cpovirkGoogle Java Core Libraries
authored andcommitted
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
1 parent eea7ac0 commit 7a1c72f

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

core/src/main/java/com/google/common/truth/AssertionErrorWithFacts.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ final class AssertionErrorWithFacts extends AssertionError implements ErrorWithF
3131

3232
AssertionErrorWithFacts(
3333
ImmutableList<String> messages, ImmutableList<Fact> facts, @Nullable Throwable cause) {
34-
super(makeMessage(messages, facts));
34+
super(makeMessage(messages, facts), cause);
3535
this.facts = checkNotNull(facts);
36-
37-
initCause(cause);
3836
}
3937

4038
@Override

core/src/main/java/com/google/common/truth/Truth.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,7 @@ public static PathSubject assertThat(@Nullable Path actual) {
355355
@SuppressWarnings("OverrideThrowableToString") // We intentionally replace the normal format.
356356
static final class SimpleAssertionError extends AssertionError {
357357
private SimpleAssertionError(String message, @Nullable Throwable cause) {
358-
super(checkNotNull(message));
359-
360-
initCause(cause);
358+
super(checkNotNull(message), cause);
361359
}
362360

363361
static SimpleAssertionError create(String message, @Nullable Throwable cause) {

0 commit comments

Comments
 (0)