Skip to content

Commit

Permalink
Remove more copies of a workaround for an ancient Android bug.
Browse files Browse the repository at this point in the history
(followup to cl/604677493)

RELNOTES=n/a
PiperOrigin-RevId: 609415936
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Feb 22, 2024
1 parent a43223e commit 996a844
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,12 @@
final class AssertionErrorWithFacts extends AssertionError implements ErrorWithFacts {
private final ImmutableList<Fact> facts;

/** Separate cause field, in case initCause() fails. */
private final @Nullable Throwable cause;

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

this.cause = cause;
try {
initCause(cause);
} catch (IllegalStateException alreadyInitializedBecauseOfHarmonyBug) {
// See Truth.SimpleAssertionError.
}
}

@Override
@SuppressWarnings("UnsynchronizedOverridesSynchronized")
public @Nullable Throwable getCause() {
return cause;
initCause(cause);
}

@Override
Expand Down
16 changes: 1 addition & 15 deletions core/src/main/java/com/google/common/truth/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,33 +165,19 @@ private static ImmutableList<String> splitLines(String s) {
abstract static class PlatformComparisonFailure extends ComparisonFailure {
private final String message;

/** Separate cause field, in case initCause() fails. */
private final @Nullable Throwable cause;

PlatformComparisonFailure(
String message, String expected, String actual, @Nullable Throwable cause) {
super(message, expected, actual);
this.message = message;
this.cause = cause;

try {
initCause(cause);
} catch (IllegalStateException alreadyInitializedBecauseOfHarmonyBug) {
// See Truth.SimpleAssertionError.
}
initCause(cause);
}

@Override
public final String getMessage() {
return message;
}

@Override
@SuppressWarnings("UnsynchronizedOverridesSynchronized")
public final @Nullable Throwable getCause() {
return cause;
}

// To avoid printing the class name before the message.
// TODO(cpovirk): Write a test that fails without this. Ditto for SimpleAssertionError.
@Override
Expand Down

0 comments on commit 996a844

Please sign in to comment.