Stopgap of NPE when searching for the definition of synthesized class.
Bug: 123737770, 113374256
Change-Id: Ia55bcf8fe0dc444b36ad04458bfaca4be3f2dc97
diff --git a/src/main/java/com/android/tools/r8/graph/DexType.java b/src/main/java/com/android/tools/r8/graph/DexType.java
index 9cdede4..936f967 100644
--- a/src/main/java/com/android/tools/r8/graph/DexType.java
+++ b/src/main/java/com/android/tools/r8/graph/DexType.java
@@ -10,6 +10,7 @@
import com.android.tools.r8.dex.IndexedItemCollection;
import com.android.tools.r8.errors.Unreachable;
+import com.android.tools.r8.logging.Log;
import com.android.tools.r8.naming.NamingLens;
import com.android.tools.r8.utils.DescriptorUtils;
import com.android.tools.r8.utils.InternalOptions.OutlineOptions;
@@ -166,6 +167,13 @@
}
public boolean isStrictSubtypeOf(DexType other, AppInfo appInfo) {
+ // For all erroneous cases, saying `no`---not a strict subtype---is conservative.
+ return isStrictSubtypeOf(other, appInfo, false);
+ }
+
+ // Depending on optimizations, conservative answer of subtype relation may vary.
+ // Pass different `orElse` in that case.
+ public boolean isStrictSubtypeOf(DexType other, AppInfo appInfo, boolean orElse) {
if (this == other) {
return false;
}
@@ -184,7 +192,7 @@
return other.directSubtypes.stream().anyMatch(subtype -> this.isSubtypeOf(subtype,
appInfo));
}
- return isSubtypeOfClass(other, appInfo);
+ return isSubtypeOfClass(other, appInfo, orElse);
}
private boolean isInterfaceSubtypeOf(DexType candidate, DexType other, AppInfo appInfo) {
@@ -204,15 +212,22 @@
return false;
}
- private boolean isSubtypeOfClass(DexType other, AppInfo appInfo) {
+ private boolean isSubtypeOfClass(DexType other, AppInfo appInfo, boolean orElse) {
DexType self = this;
if (other.hierarchyLevel == UNKNOWN_LEVEL) {
- // We have no definition for this class, hence it is not part of the
- // hierarchy.
- return false;
+ // We have no definition for this class, hence it is not part of the hierarchy.
+ return orElse;
}
while (other.hierarchyLevel < self.hierarchyLevel) {
DexClass holder = appInfo.definitionFor(self);
+ // TODO(b/113374256): even synthesized class should be available ATM.
+ if (holder == null) {
+ assert self.isD8R8SynthesizedClassType();
+ if (Log.ENABLED) {
+ Log.debug(getClass(), "%s is not in AppInfo yet.", self.toSourceString());
+ }
+ return orElse;
+ }
assert holder != null && !holder.isInterface();
self = holder.superType;
}
diff --git a/src/test/java/com/android/tools/r8/kotlin/KotlinLambdaMergingWithReprocessingTest.java b/src/test/java/com/android/tools/r8/kotlin/KotlinLambdaMergingWithReprocessingTest.java
index 31db483..343dfdf 100644
--- a/src/test/java/com/android/tools/r8/kotlin/KotlinLambdaMergingWithReprocessingTest.java
+++ b/src/test/java/com/android/tools/r8/kotlin/KotlinLambdaMergingWithReprocessingTest.java
@@ -5,7 +5,6 @@
import com.android.tools.r8.utils.InternalOptions;
import java.util.function.Consumer;
-import org.junit.Ignore;
import org.junit.Test;
public class KotlinLambdaMergingWithReprocessingTest extends AbstractR8KotlinTestBase {
@@ -18,7 +17,6 @@
o.enableLambdaMerging = true;
};
- @Ignore("b/123737770")
@Test
public void testMergingKStyleLambdasAndReprocessing() throws Exception {
final String mainClassName = "reprocess_merged_lambdas_kstyle.MainKt";