Ignore annotations for non-existent parameters

Bug: 116089492
Change-Id: I61b0cdc66172e7d50016012a2b75ab62f2030ac1
diff --git a/src/main/java/com/android/tools/r8/graph/ParameterAnnotationsList.java b/src/main/java/com/android/tools/r8/graph/ParameterAnnotationsList.java
index 343b392..97ae20c 100644
--- a/src/main/java/com/android/tools/r8/graph/ParameterAnnotationsList.java
+++ b/src/main/java/com/android/tools/r8/graph/ParameterAnnotationsList.java
@@ -151,10 +151,18 @@
 
   /** Return a ParameterAnnotationsList extended to the given number of parameters. */
   public ParameterAnnotationsList withParameterCount(int parameterCount) {
-    assert parameterCount >= size();
     if (this == EMPTY_PARAMETER_ANNOTATIONS_LIST || parameterCount == size()) {
       return this;
     }
+    if (parameterCount < size()) {
+      // Generally, it should never be the case that parameterCount < size(). However, it may be
+      // that the input has already been optimized (e.g., by Proguard), and that some optimization
+      // has removed formal parameters without removing the corresponding parameters annotations.
+      // In this case, we remove the excess annotations.
+      DexAnnotationSet[] trimmedValues = new DexAnnotationSet[parameterCount];
+      System.arraycopy(values, 0, trimmedValues, 0, parameterCount);
+      return new ParameterAnnotationsList(trimmedValues, 0);
+    }
     return new ParameterAnnotationsList(values, parameterCount - values.length);
   }
 
diff --git a/tools/run_on_app.py b/tools/run_on_app.py
index bab9b32..6493b2c 100755
--- a/tools/run_on_app.py
+++ b/tools/run_on_app.py
@@ -118,8 +118,6 @@
 # Please add bug number for disabled permutations and please explicitly
 # do Bug: #BUG in the commit message of disabling to ensure re-enabling
 DISABLED_PERMUTATIONS = [
-    ('youtube', '12.10', 'dex'), # b/116089492
-    ('youtube', '12.10', 'proguarded'), # b/116089492
     ('gmscore', 'latest', 'deploy') # b/116575775
 ]
 
diff --git a/tools/youtube_data.py b/tools/youtube_data.py
index 6fdf63a..2e3be27 100644
--- a/tools/youtube_data.py
+++ b/tools/youtube_data.py
@@ -39,12 +39,15 @@
       'pgconf': ['%s_proguard.config' % V12_10_PREFIX,
                  '%s/proguardsettings/YouTubeRelease_proguard.config' % THIRD_PARTY],
       'min-api' : ANDROID_L_API,
-    },
-    'proguarded' : {
-      'inputs': ['%s_proguard.jar' % V12_10_PREFIX],
-      'pgmap': '%s_proguard.map' % V12_10_PREFIX,
-      'min-api' : ANDROID_L_API,
     }
+    # The 'proguarded' version cannot be handled by D8/R8 because there are
+    # parameter annotations for parameters that do not exist, which is not
+    # handled gracefully by ASM (see b/116089492).
+    #'proguarded' : {
+    #  'inputs': ['%s_proguard.jar' % V12_10_PREFIX],
+    #  'pgmap': '%s_proguard.map' % V12_10_PREFIX,
+    #  'min-api' : ANDROID_L_API,
+    #}
   },
   '12.17': {
     'dex' : {