Test for unused type in throwing with keepattributes Exceptions
This is a test that reproduces the error seen in the tivi-app.
Bug: 124019003
Change-Id: I81862047d55124b8e45acb7c1b5f8668a84be9b2
diff --git a/src/test/java/com/android/tools/r8/shaking/UnusedTypeInThrowingTest.java b/src/test/java/com/android/tools/r8/shaking/UnusedTypeInThrowingTest.java
new file mode 100644
index 0000000..6a03a43
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/shaking/UnusedTypeInThrowingTest.java
@@ -0,0 +1,38 @@
+// Copyright (c) 2019, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+package com.android.tools.r8.shaking;
+
+import com.android.tools.r8.CompilationFailedException;
+import com.android.tools.r8.TestBase;
+import java.io.IOException;
+import org.junit.Ignore;
+import org.junit.Test;
+
+class UnusedTypeInThrowing {
+
+ public static void main(String[] args) throws UnusedTypeInThrowingThrowable {
+ System.out.print("42");
+ }
+}
+
+class UnusedTypeInThrowingThrowable extends Throwable {}
+
+public class UnusedTypeInThrowingTest extends TestBase {
+
+ static final Class THROWABLE_CLASS = UnusedTypeInThrowingThrowable.class;
+ static final Class MAIN_CLASS = UnusedTypeInThrowing.class;
+
+ @Test
+ @Ignore("b/124019003")
+ public void testTypeIsMarkedAsLive() throws IOException, CompilationFailedException {
+ testForR8(Backend.CF)
+ .addProgramClasses(MAIN_CLASS)
+ .addProgramClasses(THROWABLE_CLASS)
+ .addKeepMainRule(MAIN_CLASS)
+ .addKeepRules("-keepattributes Exceptions")
+ .run(MAIN_CLASS)
+ .assertSuccessWithOutput("42");
+ }
+}
diff --git a/src/test/java/com/android/tools/r8/shaking/UnusedTypeInThrowingTestRunner.java b/src/test/java/com/android/tools/r8/shaking/UnusedTypeInThrowingTestRunner.java
new file mode 100644
index 0000000..2bf42a1
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/shaking/UnusedTypeInThrowingTestRunner.java
@@ -0,0 +1,37 @@
+// Copyright (c) 2019, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+package com.android.tools.r8.shaking;
+
+import com.android.tools.r8.CompilationFailedException;
+import com.android.tools.r8.CompilationMode;
+import com.android.tools.r8.TestBase;
+import com.google.common.collect.ImmutableList;
+import java.io.IOException;
+import java.nio.file.Path;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class UnusedTypeInThrowingTestRunner extends TestBase {
+
+ static final Class THROWABLE_CLASS = UnusedTypeInThrowingThrowable.class;
+ static final Class MAIN_CLASS = UnusedTypeInThrowingTest.class;
+
+ @Test
+ @Ignore("b/124019003")
+ public void testTypeIsMarkedAsLive() throws IOException, CompilationFailedException {
+ Path outDex = temp.newFile("out.zip").toPath();
+ testForR8(Backend.CF)
+ .addProgramClasses(MAIN_CLASS)
+ .addProgramClasses(THROWABLE_CLASS)
+ .addKeepMainRule(MAIN_CLASS)
+ .addKeepRules(ImmutableList.of("-keepattributes Exceptions"))
+ .setMode(CompilationMode.RELEASE)
+ .enableInliningAnnotations()
+ .minification(true)
+ .compile()
+ .run(MAIN_CLASS)
+ .assertSuccessWithOutput("42");
+ }
+}