Revert "Include handler stack and full stack when compilation fails."
This reverts commit dae6241ce7fc46c8cd0b94327bc35208d70f2a57.
Reason for revert: Test failures
Change-Id: Iab64df0d8f4ff88c81c6cd521848a083b2ac56ca
diff --git a/src/main/java/com/android/tools/r8/utils/ExceptionUtils.java b/src/main/java/com/android/tools/r8/utils/ExceptionUtils.java
index 28d1ed5..e5ba3f1 100644
--- a/src/main/java/com/android/tools/r8/utils/ExceptionUtils.java
+++ b/src/main/java/com/android/tools/r8/utils/ExceptionUtils.java
@@ -12,7 +12,6 @@
import com.android.tools.r8.origin.Origin;
import com.android.tools.r8.origin.PathOrigin;
import com.android.tools.r8.position.Position;
-import com.google.common.collect.ObjectArrays;
import java.io.IOException;
import java.nio.file.FileSystemException;
import java.nio.file.Paths;
@@ -98,10 +97,6 @@
suppressed.add(innerMostCause);
innerMostCause = innerMostCause.getCause();
}
- // Add the full stack as a suppressed stack on the inner cause.
- if (topMostException != innerMostCause) {
- innerMostCause.addSuppressed(topMostException);
- }
// If no abort is seen, the exception is not reported, so report it now.
if (!hasBeenReported) {
@@ -121,9 +116,10 @@
new CompilationFailedException(message.toString(), innerMostCause);
// Replace its stack by the cause stack and insert version info at the top.
String filename = "Version_" + Version.LABEL + ".java";
- StackTraceElement versionElement =
- new StackTraceElement(Version.class.getSimpleName(), "fakeStackEntry", filename, 0);
- rethrow.setStackTrace(ObjectArrays.concat(versionElement, rethrow.getStackTrace()));
+ rethrow.setStackTrace(
+ new StackTraceElement[] {
+ new StackTraceElement(Version.class.getSimpleName(), "fakeStackEntry", filename, 0)
+ });
return rethrow;
}
diff --git a/src/main/java/com/android/tools/r8/utils/Reporter.java b/src/main/java/com/android/tools/r8/utils/Reporter.java
index f251b0c..f7f9d1f 100644
--- a/src/main/java/com/android/tools/r8/utils/Reporter.java
+++ b/src/main/java/com/android/tools/r8/utils/Reporter.java
@@ -5,6 +5,7 @@
import com.android.tools.r8.Diagnostic;
import com.android.tools.r8.DiagnosticsHandler;
+import com.android.tools.r8.errors.Unreachable;
public class Reporter implements DiagnosticsHandler {
@@ -55,13 +56,14 @@
*/
public RuntimeException fatalError(Diagnostic error) {
error(error);
- throw abort;
+ failIfPendingErrors();
+ throw new Unreachable();
}
/** @throws AbortException if any error was reported. */
public synchronized void failIfPendingErrors() {
if (abort != null) {
- throw new RuntimeException(abort);
+ throw abort;
}
}
}
diff --git a/src/test/java/com/android/tools/r8/diagnostics/ErrorDuringIrConversionTest.java b/src/test/java/com/android/tools/r8/diagnostics/ErrorDuringIrConversionTest.java
index b9eabe6..1f19d89 100644
--- a/src/test/java/com/android/tools/r8/diagnostics/ErrorDuringIrConversionTest.java
+++ b/src/test/java/com/android/tools/r8/diagnostics/ErrorDuringIrConversionTest.java
@@ -28,7 +28,6 @@
import java.io.StringWriter;
import java.util.concurrent.atomic.AtomicBoolean;
import org.hamcrest.Matcher;
-import org.hamcrest.core.IsAnything;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -36,6 +35,8 @@
@RunWith(Parameterized.class)
public class ErrorDuringIrConversionTest extends TestBase {
+ static final String EXPECTED = StringUtils.lines("Hello, world");
+
static final Origin ORIGIN =
new Origin(Origin.root()) {
@Override
@@ -60,21 +61,10 @@
CompilationFailedException e, Matcher<String> messageMatcher, Matcher<String> stackMatcher) {
// Check that the failure exception exiting the compiler contains origin info in the message.
assertThat(e.getMessage(), messageMatcher);
+ // Check that the stack trace has the version marker.
StringWriter writer = new StringWriter();
e.printStackTrace(new PrintWriter(writer));
- String fullStackTrace = writer.toString();
- // Extract the top cause stack.
- int topStackTraceEnd = fullStackTrace.indexOf("Caused by:");
- String topStackTrace = fullStackTrace.substring(0, topStackTraceEnd);
- String restStackTrace = fullStackTrace.substring(topStackTraceEnd);
- // Check that top stack trace always has the version marker.
- assertThat(topStackTrace, containsString("fakeStackEntry"));
- // Check that top stack has the D8 entry (from tests the non-renamed entry is ToolHelper.runD8).
- assertThat(topStackTrace, containsString("com.android.tools.r8.ToolHelper.runD8("));
- // Check that the stack trace always has the suppressed info.
- assertThat(restStackTrace, containsString(StringUtils.LINE_SEPARATOR + "\tSuppressed:"));
- // Custom test checks.
- assertThat(restStackTrace, stackMatcher);
+ assertThat(writer.toString(), stackMatcher);
}
private static void throwNPE() {
@@ -100,7 +90,9 @@
});
} catch (CompilationFailedException e) {
checkCompilationFailedException(
- e, containsString(ORIGIN.toString()), containsString("throwNPE"));
+ e,
+ containsString(ORIGIN.toString()),
+ allOf(containsString("fakeStackEntry"), containsString("throwNPE")));
return;
}
fail("Expected compilation to fail");
@@ -130,7 +122,8 @@
diagnosticOrigin(Origin.unknown())));
});
} catch (CompilationFailedException e) {
- checkCompilationFailedException(e, containsString(ORIGIN.toString()), new IsAnything<>());
+ checkCompilationFailedException(
+ e, containsString(ORIGIN.toString()), containsString("fakeStackEntry"));
return;
}
fail("Expected compilation to fail");
@@ -180,9 +173,10 @@
// There may be no fail-if-error barrier inside any origin association, thus only the
// top level message can be expected here.
containsString("Compilation failed to complete"),
- // The stack trace must contain the reportErrors frame for the hook above, and one
+ // The stack trace must contain both the version, the frame for the hook above, and one
// of the error messages.
allOf(
+ containsString("fakeStackEntry"),
containsString("reportErrors"),
anyOf(containsString("FOO!"), containsString("BAR!"), containsString("BAZ!"))));
return;