Fix NPE from rewriting of missing classes contexts
Bug: b/236615030
Change-Id: Ib9d194d870ba79be2f8f704666100388fc8d0db7
diff --git a/src/main/java/com/android/tools/r8/shaking/MissingClasses.java b/src/main/java/com/android/tools/r8/shaking/MissingClasses.java
index 5e33712..31b323b 100644
--- a/src/main/java/com/android/tools/r8/shaking/MissingClasses.java
+++ b/src/main/java/com/android/tools/r8/shaking/MissingClasses.java
@@ -204,14 +204,22 @@
assert !synthesizingContextReferences.isEmpty();
for (DexReference synthesizingContextReference : synthesizingContextReferences) {
if (synthesizingContextReference.isDexMethod()) {
- DexProgramClass holder =
+ DexProgramClass synthesizingContextHolder =
appView
.definitionFor(synthesizingContextReference.getContextType())
.asProgramClass();
ProgramMethod synthesizingContext =
- holder.lookupProgramMethod(synthesizingContextReference.asDexMethod());
- assert synthesizingContext != null;
- rewrittenContexts.add(synthesizingContext);
+ synthesizingContextHolder.lookupProgramMethod(
+ synthesizingContextReference.asDexMethod());
+ if (synthesizingContext != null) {
+ rewrittenContexts.add(synthesizingContext);
+ } else {
+ // The synthesizing context no longer exists. It must have been forcefully moved due
+ // to desugaring. For now we report the holder of the synthesizing context as the
+ // origin of the missing class reference.
+ assert synthesizingContextHolder.isInterface();
+ rewrittenContexts.add(synthesizingContextHolder);
+ }
} else if (synthesizingContextReference.isDexType()) {
DexProgramClass synthesizingClass =
appView.definitionFor(synthesizingContextReference.asDexType()).asProgramClass();