From affa37ac76a9bd726e46ad6108a707436fdfeded Mon Sep 17 00:00:00 2001 From: ghm Date: Thu, 14 Dec 2023 04:37:27 -0800 Subject: [PATCH] Do not flag unused parameters on _abstract_ methods. I think this was introduced in https://github.com/google/error-prone/commit/88a224c9f00deca8757fd864a8d29941cff1ac12, where we suddenly start considering some _effectively_ private abstract methods. PiperOrigin-RevId: 590895990 --- .../java/com/google/errorprone/bugpatterns/UnusedVariable.java | 3 ++- .../com/google/errorprone/bugpatterns/UnusedVariableTest.java | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/UnusedVariable.java b/core/src/main/java/com/google/errorprone/bugpatterns/UnusedVariable.java index 4622c14cae5..8f2955ad0f6 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/UnusedVariable.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/UnusedVariable.java @@ -706,7 +706,8 @@ private boolean isParameterSubjectToAnalysis(Symbol sym) { checkArgument(sym.getKind() == ElementKind.PARAMETER); Symbol enclosingMethod = sym.owner; - if (!(enclosingMethod instanceof MethodSymbol)) { + if (!(enclosingMethod instanceof MethodSymbol) + || isAbstract((MethodSymbol) enclosingMethod)) { return false; } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/UnusedVariableTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/UnusedVariableTest.java index 76ccd5999b8..79da2f90e8f 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/UnusedVariableTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/UnusedVariableTest.java @@ -263,6 +263,9 @@ public void unusedParamInPrivateMethod() { " System.out.println(i);", " }", " }", + " private interface Foo {", + " void foo(int a);", + " }", " public void main() {", " test(1, 2);", " }",