diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/MemberName.java b/core/src/main/java/com/google/errorprone/bugpatterns/MemberName.java index 15b7bee933f8..5c2f63e7ae0f 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/MemberName.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/MemberName.java @@ -49,6 +49,7 @@ import com.google.errorprone.suppliers.Supplier; import com.google.errorprone.util.ASTHelpers; import com.sun.source.tree.MethodTree; +import com.sun.source.tree.Tree.Kind; import com.sun.source.tree.VariableTree; import com.sun.tools.javac.code.Symbol; import com.sun.tools.javac.code.Symbol.MethodSymbol; @@ -143,7 +144,9 @@ private static boolean hasTestAnnotation(MethodSymbol symbol) { public Description matchVariable(VariableTree tree, VisitorState state) { VarSymbol symbol = getSymbol(tree); String name = tree.getName().toString(); - if (symbol.owner instanceof MethodSymbol && symbol.getKind().equals(ElementKind.PARAMETER)) { + if (symbol.owner instanceof MethodSymbol + && symbol.getKind() == ElementKind.PARAMETER + && state.getPath().getParentPath().getLeaf().getKind() != Kind.LAMBDA_EXPRESSION) { var methodSymbol = (MethodSymbol) symbol.owner; int index = methodSymbol.getParameters().indexOf(symbol); var maybeSuper = ASTHelpers.streamSuperMethods(methodSymbol, state.getTypes()).findFirst(); diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/MemberNameTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/MemberNameTest.java index d12764996c07..4a4438ee6031 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/MemberNameTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/MemberNameTest.java @@ -413,4 +413,21 @@ public void initialismsInVariableNames_magicNamesExempt() { "}") .doTest(); } + + @Test + public void lambdaExpressionParameterInsideOverridingMethod() { + helper + .addSourceLines( + "Test.java", + "import java.util.function.Function;", + "class Test {", + " @Override", + " public String toString() {", + " // BUG: Diagnostic contains: fooBar", + " Function f = foo_bar -> foo_bar;", + " return f.apply(\"foo\");", + " }", + "}") + .doTest(); + } }