Skip adding pending synthetics to classpath classes
Change-Id: I488400a06655b6a9794da3f05198d9d9681a2336
diff --git a/src/main/java/com/android/tools/r8/shaking/Enqueuer.java b/src/main/java/com/android/tools/r8/shaking/Enqueuer.java
index c5238b0..f2bf9a4 100644
--- a/src/main/java/com/android/tools/r8/shaking/Enqueuer.java
+++ b/src/main/java/com/android/tools/r8/shaking/Enqueuer.java
@@ -4600,11 +4600,20 @@
if (clazz.isLibraryClass()) {
libraryClasses.add(clazz.asLibraryClass());
} else if (clazz.isClasspathClass()) {
- classpathClasses.add(clazz.asClasspathClass());
+ DexClasspathClass classpathClass = clazz.asClasspathClass();
+ if (appView.getSyntheticItems().isPendingSynthetic(classpathClass.getType())) {
+ // This class will be committed later.
+ } else {
+ classpathClasses.add(classpathClass);
+ }
} else {
assert false;
}
}
+ // Verify the synthetic classpath classes are live before we commit them to the app below.
+ assert appView.getSyntheticItems().getPendingSyntheticClasses().stream()
+ .filter(DexClass::isClasspathClass)
+ .allMatch(liveNonProgramTypes::contains);
// Add just referenced non-program types. We can't replace the program classes at this point as
// they are needed in tree pruning.
diff --git a/src/test/java/com/android/tools/r8/regress/b426351560/Regress427887773Test.java b/src/test/java/com/android/tools/r8/regress/b426351560/Regress427887773Test.java
index 76b7c51..a15a998 100644
--- a/src/test/java/com/android/tools/r8/regress/b426351560/Regress427887773Test.java
+++ b/src/test/java/com/android/tools/r8/regress/b426351560/Regress427887773Test.java
@@ -3,16 +3,10 @@
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8.regress.b426351560;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-import com.android.tools.r8.CompilationFailedException;
import com.android.tools.r8.TestBase;
import com.android.tools.r8.TestParameters;
import com.android.tools.r8.TestParametersCollection;
import com.android.tools.r8.regress.b426351560.testclasses.Regress426351560TestClasses;
-import com.android.tools.r8.utils.AndroidApiLevel;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -32,23 +26,14 @@
@Test
public void testR8() throws Exception {
- try {
- testForR8(parameters)
- .addInnerClasses(getClass())
- .addClasspathClasses(Regress426351560TestClasses.getClasses())
- .addKeepRules("-keep class " + Main.class.getTypeName() + " { *; }")
- .compile()
- .addRunClasspathClasses(Regress426351560TestClasses.getClasses())
- .run(parameters.getRuntime(), Main.class)
- .assertSuccessWithOutputLines("Hello, world!");
- } catch (CompilationFailedException e) {
- if (parameters.isDexRuntime() && parameters.getApiLevel().isLessThan(AndroidApiLevel.N)) {
- assertTrue(e.getCause() instanceof AssertionError);
- assertThat(e.getCause().getMessage(), containsString("CC was already present."));
- } else {
- throw e;
- }
- }
+ testForR8(parameters)
+ .addInnerClasses(getClass())
+ .addClasspathClasses(Regress426351560TestClasses.getClasses())
+ .addKeepRules("-keep class " + Main.class.getTypeName() + " { *; }")
+ .compile()
+ .addRunClasspathClasses(Regress426351560TestClasses.getClasses())
+ .run(parameters.getRuntime(), Main.class)
+ .assertSuccessWithOutputLines("Hello, world!");
}
public static class Main extends Regress426351560TestClasses.A {