Add test for -printseeds with $deserializeLambda$ methods and no tree shaking

Bug: 170716961
Change-Id: I43009dd691a3d21f579fb66dc4d9621c9247907d
diff --git a/src/main/java/com/android/tools/r8/shaking/RootSetBuilder.java b/src/main/java/com/android/tools/r8/shaking/RootSetBuilder.java
index 8419104..36b5b7a 100644
--- a/src/main/java/com/android/tools/r8/shaking/RootSetBuilder.java
+++ b/src/main/java/com/android/tools/r8/shaking/RootSetBuilder.java
@@ -717,6 +717,10 @@
         }
         out.print(method.holder.toSourceString() + ": ");
         DexEncodedMethod encodedMethod = appInfo.definitionFor(method);
+        if (encodedMethod == null) {
+          assert method.match(appInfo.dexItemFactory().deserializeLambdaMethod);
+          continue;
+        }
         if (encodedMethod.accessFlags.isConstructor()) {
           if (encodedMethod.accessFlags.isStatic()) {
             out.print(Constants.CLASS_INITIALIZER_NAME);
diff --git a/src/test/java/com/android/tools/r8/TestShrinkerBuilder.java b/src/test/java/com/android/tools/r8/TestShrinkerBuilder.java
index a088c00..3e181b0 100644
--- a/src/test/java/com/android/tools/r8/TestShrinkerBuilder.java
+++ b/src/test/java/com/android/tools/r8/TestShrinkerBuilder.java
@@ -220,6 +220,10 @@
     return self();
   }
 
+  public T addPrintSeeds() {
+    return addKeepRules("-printseeds");
+  }
+
   public T allowAccessModification() {
     return allowAccessModification(true);
   }
diff --git a/src/test/java/com/android/tools/r8/cf/PrintSeedsWithDeserializeLambdaMethodTest.java b/src/test/java/com/android/tools/r8/cf/PrintSeedsWithDeserializeLambdaMethodTest.java
new file mode 100644
index 0000000..497a1bf
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/cf/PrintSeedsWithDeserializeLambdaMethodTest.java
@@ -0,0 +1,74 @@
+// Copyright (c) 2020, 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.cf;
+
+import static org.junit.Assert.assertEquals;
+
+import com.android.tools.r8.TestBase;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import com.android.tools.r8.utils.StringUtils;
+import com.android.tools.r8.utils.codeinspector.CodeInspector;
+import com.android.tools.r8.utils.codeinspector.MethodSubject;
+import com.google.common.collect.ImmutableList;
+import java.util.List;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class PrintSeedsWithDeserializeLambdaMethodTest extends TestBase {
+
+  private static final Class<?> TEST_CLASS_CF = KeepDeserializeLambdaMethodTestCf.class;
+  private static final Class<?> TEST_CLASS_DEX = KeepDeserializeLambdaMethodTestDex.class;
+
+  private static final String EXPECTED =
+      StringUtils.lines("base lambda", KeepDeserializeLambdaMethodTest.LAMBDA_MESSAGE);
+
+  @Parameters(name = "{0}")
+  public static TestParametersCollection params() {
+    return getTestParameters().withAllRuntimesAndApiLevels().build();
+  }
+
+  private final TestParameters parameters;
+
+  public PrintSeedsWithDeserializeLambdaMethodTest(TestParameters parameters) {
+    this.parameters = parameters;
+  }
+
+  private Class<?> getMainClass() {
+    return parameters.isCfRuntime() ? TEST_CLASS_CF : TEST_CLASS_DEX;
+  }
+
+  private List<Class<?>> getClasses() {
+    return ImmutableList.of(KeepDeserializeLambdaMethodTest.class, getMainClass());
+  }
+
+  @Test
+  public void test() throws Exception {
+    testForR8Compat(parameters.getBackend())
+        .addProgramClasses(getClasses())
+        .setMinApi(parameters.getApiLevel())
+        .addKeepMainRule(getMainClass())
+        .addPrintSeeds()
+        .allowStdoutMessages()
+        .noMinification()
+        .noTreeShaking()
+        .run(parameters.getRuntime(), getMainClass())
+        .assertSuccessWithOutput(EXPECTED)
+        .inspect(this::checkPresenceOfDeserializedLambdas);
+  }
+
+  private void checkPresenceOfDeserializedLambdas(CodeInspector inspector) {
+    for (Class<?> clazz : getClasses()) {
+      MethodSubject method = inspector.clazz(clazz).uniqueMethodWithName("$deserializeLambda$");
+      assertEquals(
+          "Unexpected status for $deserializedLambda$ on " + clazz.getSimpleName(),
+          parameters.isCfRuntime(),
+          method.isPresent());
+    }
+  }
+}