diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/RedundantLambdaCodeBlockInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/RedundantLambdaCodeBlockInspection.java index 0812914d95d3..829872f2010d 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/RedundantLambdaCodeBlockInspection.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/RedundantLambdaCodeBlockInspection.java @@ -87,7 +87,8 @@ public class RedundantLambdaCodeBlockInspection extends BaseJavaBatchLocalInspec if (psiExpression != null && !findCommentsOutsideExpression(body, psiExpression)) { if (LambdaUtil.isExpressionStatementExpression(psiExpression)) { final PsiCall call = LambdaUtil.treeWalkUp(body); - if (call != null && call.resolveMethod() != null) { + PsiMethod oldTarget; + if (call != null && (oldTarget = call.resolveMethod()) != null) { final int offsetInTopCall = body.getTextRange().getStartOffset() - call.getTextRange().getStartOffset(); PsiCall copyCall = LambdaUtil.copyTopLevelCall(call); if (copyCall == null) return null; @@ -96,7 +97,7 @@ public class RedundantLambdaCodeBlockInspection extends BaseJavaBatchLocalInspec final PsiElement parent = codeBlock.getParent(); if (parent instanceof PsiLambdaExpression) { codeBlock.replace(psiExpression); - if (copyCall.resolveMethod() == null || ((PsiLambdaExpression)parent).getFunctionalInterfaceType() == null) { + if (copyCall.resolveMethod() != oldTarget || ((PsiLambdaExpression)parent).getFunctionalInterfaceType() == null) { return null; } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/anonymous2lambda/afterSameOverload.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/anonymous2lambda/afterSameOverload.java index 41c66a5d0019..095483069464 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/anonymous2lambda/afterSameOverload.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/anonymous2lambda/afterSameOverload.java @@ -9,6 +9,8 @@ class A { } public static void main(String[] args) { - submit((Runnable) () -> new A()); + submit(() -> { + new A(); + }); } } \ No newline at end of file