Fix VarargRemoval logic

Test: Compatibility tests
Bug: 217429106
Change-Id: I6f8499c2ecbbdba5b22db9de5f6129b49d1d68b7
diff --git a/src/main/java/com/android/tools/metalava/CompatibilityCheck.kt b/src/main/java/com/android/tools/metalava/CompatibilityCheck.kt
index 119c545..98d54bb 100644
--- a/src/main/java/com/android/tools/metalava/CompatibilityCheck.kt
+++ b/src/main/java/com/android/tools/metalava/CompatibilityCheck.kt
@@ -176,20 +176,22 @@
     }
 
     override fun compare(old: ParameterItem, new: ParameterItem) {
-        val prevName = old.publicName() ?: return
+        val prevName = old.publicName()
         val newName = new.publicName()
-        if (newName == null) {
-            report(
-                Issues.PARAMETER_NAME_CHANGE,
-                new,
-                "Attempted to remove parameter name from ${describe(new)}"
-            )
-        } else if (newName != prevName) {
-            report(
-                Issues.PARAMETER_NAME_CHANGE,
-                new,
-                "Attempted to change parameter name from $prevName to $newName in ${describe(new.containingMethod())}"
-            )
+        if (prevName != null) {
+            if (newName == null) {
+                report(
+                    Issues.PARAMETER_NAME_CHANGE,
+                    new,
+                    "Attempted to remove parameter name from ${describe(new)}"
+                )
+            } else if (newName != prevName) {
+                report(
+                    Issues.PARAMETER_NAME_CHANGE,
+                    new,
+                    "Attempted to change parameter name from $prevName to $newName in ${describe(new.containingMethod())}"
+                )
+            }
         }
 
         if (old.hasDefaultValue() && !new.hasDefaultValue()) {
diff --git a/src/test/java/com/android/tools/metalava/binarycompatibility/BinaryCompatibilityClassMethodsAndConstructors.kt b/src/test/java/com/android/tools/metalava/binarycompatibility/BinaryCompatibilityClassMethodsAndConstructors.kt
index b7abbf3..758d5f0 100644
--- a/src/test/java/com/android/tools/metalava/binarycompatibility/BinaryCompatibilityClassMethodsAndConstructors.kt
+++ b/src/test/java/com/android/tools/metalava/binarycompatibility/BinaryCompatibilityClassMethodsAndConstructors.kt
@@ -579,44 +579,48 @@
             """
         )
     }
+    */
+
     @Test
     fun `Change last parameter from array type T(array) to variable arity T(elipse) (Compatible)`() {
         check(
             signatureSource = """
                 package test.pkg {
-                  class Foo {
-                    method public <T> void bar(T...);
-                  }
+                    class Foo {
+                        method public <T> void bar(T...);
+                    }
                 }
             """,
             checkCompatibilityApiReleased = """
                 package test.pkg {
-                  class Foo {
-                    method public <T> void bar(T[]);
-                  }
-                }
-            """
-        )
-    }
-    @Test
-    fun `Change last parameter from variable arity T(elipse) to array type T(array) (Incompatible)`() {
-        check(
-            signatureSource = """
-                package test.pkg {
-                  class Foo {
-                    method public <T> void bar(T[]);
-                  }
-                }
-            """,
-            checkCompatibilityApiReleased = """
-                package test.pkg {
-                  class Foo {
-                    method public <T> void bar(T...);
-                  }
+                    class Foo {
+                        method public <T> void bar(T[]);
+                    }
                 }
             """
         )
     }
 
-    */
+    @Test
+    fun `Change last parameter from variable arity T(elipse) to array type T(array) (Incompatible)`() {
+        check(
+            expectedIssues = """
+                TESTROOT/load-api.txt:3: error: Changing from varargs to array is an incompatible change: parameter arg1 in test.pkg.Foo.bar(T[] arg1) [VarargRemoval]
+            """,
+            signatureSource = """
+                package test.pkg {
+                    class Foo {
+                        method public <T> void bar(T[]);
+                    }
+                }
+            """,
+            checkCompatibilityApiReleased = """
+                package test.pkg {
+                    class Foo {
+                        method public <T> void bar(T...);
+                    }
+                }
+            """
+        )
+    }
 }
diff --git a/src/test/java/com/android/tools/metalava/binarycompatibility/BinaryCompatibilityInterfaceMethodsTest.kt b/src/test/java/com/android/tools/metalava/binarycompatibility/BinaryCompatibilityInterfaceMethodsTest.kt
index 168ea59..04e74f4 100644
--- a/src/test/java/com/android/tools/metalava/binarycompatibility/BinaryCompatibilityInterfaceMethodsTest.kt
+++ b/src/test/java/com/android/tools/metalava/binarycompatibility/BinaryCompatibilityInterfaceMethodsTest.kt
@@ -414,22 +414,23 @@
             """
         )
     }
+     */
 
     @Test
     fun `Change last parameter from array type T(array) to variable arity T(elipse) (Compatible)`() {
         check(
             signatureSource = """
                 package test.pkg {
-                  class Foo {
-                    method public <T> void bar(T...);
-                  }
+                    interface Foo {
+                        method public <T> void bar(T...);
+                    }
                 }
             """,
             checkCompatibilityApiReleased = """
                 package test.pkg {
-                  class Foo {
-                    method public <T> void bar(T[]);
-                  }
+                    interface Foo {
+                        method public <T> void bar(T[]);
+                    }
                 }
             """
         )
@@ -438,25 +439,26 @@
     @Test
     fun `Change last parameter from variable arity T(elipse) to array type T(array) (Incompatible)`() {
         check(
+            expectedIssues = """
+                TESTROOT/load-api.txt:3: error: Changing from varargs to array is an incompatible change: parameter arg1 in test.pkg.Foo.bar(T[] arg1) [VarargRemoval]
+            """,
             signatureSource = """
                 package test.pkg {
-                  class Foo {
-                    method public <T> void bar(T[]);
-                  }
+                    interface Foo {
+                        method public <T> void bar(T[]);
+                    }
                 }
             """,
             checkCompatibilityApiReleased = """
                 package test.pkg {
-                  class Foo {
-                    method public <T> void bar(T...);
-                  }
+                    interface Foo {
+                        method public <T> void bar(T...);
+                    }
                 }
             """
         )
     }
 
-     */
-
     @Test
     fun `Add default clause to annotation type element (Compatible)`() {
         check(