Warnings and bail outs instead of Assertion failures
Bug: 228345146
Change-Id: I20478db2e4f934af84928f8c0a9323539ffac69a
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/specificationconversion/LegacyToHumanSpecificationConverter.java b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/specificationconversion/LegacyToHumanSpecificationConverter.java
index bd26b562..7e0daab 100644
--- a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/specificationconversion/LegacyToHumanSpecificationConverter.java
+++ b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/specificationconversion/LegacyToHumanSpecificationConverter.java
@@ -32,6 +32,7 @@
import com.android.tools.r8.utils.AndroidApiLevel;
import com.android.tools.r8.utils.InternalOptions;
import com.android.tools.r8.utils.Pair;
+import com.android.tools.r8.utils.Reporter;
import com.android.tools.r8.utils.Timing;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@@ -40,14 +41,18 @@
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
public class LegacyToHumanSpecificationConverter {
private static final String WRAPPER_PREFIX = "__wrapper__.";
private static final AndroidApiLevel LEGACY_HACK_LEVEL = AndroidApiLevel.N_MR1;
private final Timing timing;
+ private final Set<String> missingClasses = new HashSet<>();
+ private final Set<String> missingMethods = new HashSet<>();
public LegacyToHumanSpecificationConverter(Timing timing) {
this.timing = timing;
@@ -89,6 +94,7 @@
convertRewritingFlagMap(legacySpec.getLibraryFlags(), app, origin);
legacyLibraryFlagHacks(libraryFlags, app, origin);
+ reportWarnings(app.options.reporter);
MultiAPILevelHumanDesugaredLibrarySpecification humanSpec =
new MultiAPILevelHumanDesugaredLibrarySpecification(
@@ -135,12 +141,30 @@
humanRewritingFlags = builder.build();
timing.end();
}
-
+ reportWarnings(app.options.reporter);
timing.end();
return new HumanDesugaredLibrarySpecification(
humanTopLevelFlags, humanRewritingFlags, legacySpec.isLibraryCompilation());
}
+ private void reportWarnings(Reporter reporter) {
+ String errorSdk = "This usually means that the compilation SDK is absent or too old.";
+ if (!missingClasses.isEmpty()) {
+ reporter.warning(
+ "Cannot retarget core lib member for missing classes: "
+ + missingClasses
+ + ". "
+ + errorSdk);
+ }
+ if (!missingMethods.isEmpty()) {
+ reporter.warning(
+ "Should have found a method (library specifications) for "
+ + missingMethods
+ + ". "
+ + errorSdk);
+ }
+ }
+
private void legacyLibraryFlagHacks(
Int2ObjectArrayMap<HumanRewritingFlags> libraryFlags, DexApplication app, Origin origin) {
int level = LEGACY_HACK_LEVEL.getLevel();
@@ -257,7 +281,11 @@
typeMap.forEach(
(type, rewrittenType) -> {
DexClass dexClass = app.definitionFor(type);
- assert dexClass != null;
+ if (dexClass == null) {
+ assert false : "Cannot retarget core lib member for missing class " + type;
+ missingClasses.add(type.toSourceString());
+ return;
+ }
List<DexClassAndMethod> methodsWithName =
findMethodsWithName(name, dexClass, builder, app);
for (DexClassAndMethod dexClassAndMethod : methodsWithName) {
@@ -297,12 +325,11 @@
DexEncodedMethod.builder().setMethod(method).setAccessFlags(flags).build();
return ImmutableList.of(DexClassAndMethod.create(clazz, build));
}
- assert !found.isEmpty()
- : "Should have found a method (library specifications) for "
- + clazz.toSourceString()
- + "."
- + methodName
- + ". Maybe the library used for the compilation should be newer.";
+ if (found.isEmpty()) {
+ String warning = clazz.toSourceString() + "." + methodName;
+ assert false : "Should have found a method (library specifications) for " + warning;
+ missingMethods.add(warning);
+ }
return found;
}