Desugared library: Invalid missing class warnings

Bug: 155423440
Change-Id: I128c2213106cc968345af90cd766f2e981d69292
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/DesugaredLibraryWrapperSynthesizer.java b/src/main/java/com/android/tools/r8/ir/desugar/DesugaredLibraryWrapperSynthesizer.java
index e3c15ae..5fbf3df 100644
--- a/src/main/java/com/android/tools/r8/ir/desugar/DesugaredLibraryWrapperSynthesizer.java
+++ b/src/main/java/com/android/tools/r8/ir/desugar/DesugaredLibraryWrapperSynthesizer.java
@@ -99,7 +99,8 @@
   public static final String VIVIFIED_TYPE_WRAPPER_SUFFIX = "$-V-WRP";
 
   private final AppView<?> appView;
-  private final DexString dexWrapperPrefix;
+  private final String dexWrapperPrefixString;
+  private final DexString dexWrapperPrefixDexString;
   private final Map<DexType, DexType> typeWrappers = new ConcurrentHashMap<>();
   private final Map<DexType, DexType> vivifiedTypeWrappers = new ConcurrentHashMap<>();
   // The invalidWrappers are wrappers with incorrect behavior because of final methods that could
@@ -114,13 +115,14 @@
   DesugaredLibraryWrapperSynthesizer(AppView<?> appView, DesugaredLibraryAPIConverter converter) {
     this.appView = appView;
     this.factory = appView.dexItemFactory();
-    this.dexWrapperPrefix = factory.createString("L" + WRAPPER_PREFIX);
+    dexWrapperPrefixString = "L" + appView.options().synthesizedClassPrefix + WRAPPER_PREFIX;
+    dexWrapperPrefixDexString = factory.createString(dexWrapperPrefixString);
     this.converter = converter;
     this.vivifiedSourceFile = appView.dexItemFactory().createString("vivified");
   }
 
   boolean hasSynthesized(DexType type) {
-    return type.descriptor.startsWith(dexWrapperPrefix);
+    return type.descriptor.startsWith(dexWrapperPrefixDexString);
   }
 
   boolean canGenerateWrapper(DexType type) {
@@ -145,12 +147,7 @@
 
   private DexType createWrapperType(DexType type, String suffix) {
     return factory.createType(
-        "L"
-            + appView.options().synthesizedClassPrefix
-            + WRAPPER_PREFIX
-            + type.toString().replace('.', '$')
-            + suffix
-            + ";");
+        dexWrapperPrefixString + type.toString().replace('.', '$') + suffix + ";");
   }
 
   private DexType getWrapper(DexType type, String suffix, Map<DexType, DexType> wrappers) {
diff --git a/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/DesugaredLibraryWarningTest.java b/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/DesugaredLibraryWarningTest.java
new file mode 100644
index 0000000..8dd0d27
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/DesugaredLibraryWarningTest.java
@@ -0,0 +1,71 @@
+// 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.desugar.desugaredlibrary;
+
+import com.android.tools.r8.CompilationMode;
+import com.android.tools.r8.L8Command;
+import com.android.tools.r8.OutputMode;
+import com.android.tools.r8.StringResource;
+import com.android.tools.r8.TestDiagnosticMessagesImpl;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.ToolHelper;
+import com.android.tools.r8.origin.Origin;
+import com.android.tools.r8.utils.AndroidApiLevel;
+import com.android.tools.r8.utils.BooleanUtils;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.List;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class DesugaredLibraryWarningTest extends DesugaredLibraryTestBase {
+
+  private static final String FUNCTION_KEEP =
+      "-keep class j$.util.function.Function$-CC {\n"
+          + "    j$.util.function.Function $default$compose(j$.util.function.Function,"
+          + " j$.util.function.Function);\n"
+          + "    j$.util.function.Function $default$andThen(j$.util.function.Function,"
+          + " j$.util.function.Function);\n"
+          + "}\n"
+          + "-keep class j$.util.function.Function { *; }";
+
+  private final TestParameters parameters;
+  private final boolean shrinkDesugaredLibrary;
+
+  @Parameterized.Parameters(name = "{1}, shrinkDesugaredLibrary: {0}")
+  public static List<Object[]> data() {
+    return buildParameters(
+        BooleanUtils.values(), getTestParameters().withDexRuntimes().withAllApiLevels().build());
+  }
+
+  public DesugaredLibraryWarningTest(boolean shrinkDesugaredLibrary, TestParameters parameters) {
+    this.shrinkDesugaredLibrary = shrinkDesugaredLibrary;
+    this.parameters = parameters;
+  }
+
+  @Test
+  public void testDesugaredLibraryContent() throws Exception {
+    TestDiagnosticMessagesImpl diagnosticsHandler = new TestDiagnosticMessagesImpl();
+    Path desugaredLib = temp.newFolder().toPath().resolve("desugar_jdk_libs_dex.zip");
+    L8Command.Builder l8Builder =
+        L8Command.builder(diagnosticsHandler)
+            .addLibraryFiles(ToolHelper.getAndroidJar(AndroidApiLevel.P))
+            .addProgramFiles(ToolHelper.getDesugarJDKLibs())
+            .addProgramFiles(ToolHelper.DESUGAR_LIB_CONVERSIONS)
+            .setMode(shrinkDesugaredLibrary ? CompilationMode.RELEASE : CompilationMode.DEBUG)
+            .addDesugaredLibraryConfiguration(
+                StringResource.fromFile(ToolHelper.DESUGAR_LIB_JSON_FOR_TESTING))
+            .setMinApiLevel(parameters.getApiLevel().getLevel())
+            .setOutput(desugaredLib, OutputMode.DexIndexed);
+    if (shrinkDesugaredLibrary) {
+      l8Builder.addProguardConfiguration(
+          Arrays.asList(FUNCTION_KEEP.split(System.lineSeparator())), Origin.unknown());
+    }
+    ToolHelper.runL8(l8Builder.build(), options -> {});
+    diagnosticsHandler.assertNoMessages();
+  }
+}