From 8a50d95092a206d727878330f954f2cff98b5ba7 Mon Sep 17 00:00:00 2001 From: cpovirk Date: Tue, 6 Feb 2024 08:31:46 -0800 Subject: [PATCH] Remove workaround for ancient Android bug. We no longer support Ice Cream Sandwich, so we no longer need to work around its bugs. (The special handling was introduced in cl/177472149.) RELNOTES=n/a PiperOrigin-RevId: 604656813 --- .../java/com/google/common/truth/Truth.java | 37 ++----------------- 1 file changed, 4 insertions(+), 33 deletions(-) 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 2d9e3a42c..837a7f20b 100644 --- a/core/src/main/java/com/google/common/truth/Truth.java +++ b/core/src/main/java/com/google/common/truth/Truth.java @@ -330,39 +330,16 @@ public static PathSubject assertThat(@Nullable Path actual) { } /** - * An {@code AssertionError} that (a) always supports a cause, even under old versions of Android - * and (b) omits "java.lang.AssertionError:" from the beginning of its toString() representation. + * An {@code AssertionError} that omits "java.lang.AssertionError:" from the beginning of its + * toString() representation. */ // TODO(cpovirk): Consider eliminating this, adding its functionality to AssertionErrorWithFacts? @SuppressWarnings("OverrideThrowableToString") // We intentionally replace the normal format. static final class SimpleAssertionError extends AssertionError { - /** Separate cause field, in case initCause() fails. */ - private final @Nullable Throwable cause; - private SimpleAssertionError(String message, @Nullable Throwable cause) { super(checkNotNull(message)); - this.cause = cause; - - try { - initCause(cause); - } catch (IllegalStateException alreadyInitializedBecauseOfHarmonyBug) { - /* - * initCause() throws under old versions of Android: - * https://issuetracker.google.com/issues/36945167 - * - * Yes, it's *nice* if initCause() works: - * - * - It ensures that, if someone tries to call initCause() later, the call will fail loudly - * rather than be silently ignored. - * - * - It populates the usual `Throwable.cause` field, where users of debuggers and other - * tools are likely to look first. - * - * But if it doesn't work, that's fine: Most consumers of the cause should be retrieving it - * through getCause(), which we've overridden to return *our* `cause` field, which we've - * populated with the correct value. - */ - } + + initCause(cause); } static SimpleAssertionError create(String message, @Nullable Throwable cause) { @@ -379,12 +356,6 @@ static SimpleAssertionError createWithNoStack(String message) { return createWithNoStack(message, /* cause= */ null); } - @Override - @SuppressWarnings("UnsynchronizedOverridesSynchronized") - public @Nullable Throwable getCause() { - return cause; - } - @Override public String toString() { return checkNotNull(getLocalizedMessage());