From 51e23e60633aa74078e2d5a5a219f042887bd195 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 16 Apr 2015 16:58:39 +0300 Subject: [PATCH] IDEA-139301 "Constant conditions & exceptions" flaggs nullable expression when implementing a method returning void --- .../dataFlow/StandardDataFlowRunner.java | 2 +- .../dataFlow/fixture/NullableVoidLambda.java | 12 ++++++++++++ .../codeInspection/DataFlowInspection8Test.java | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/inspection/dataFlow/fixture/NullableVoidLambda.java diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/StandardDataFlowRunner.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/StandardDataFlowRunner.java index 4f9108befb17..0d951c81f11d 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/StandardDataFlowRunner.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/StandardDataFlowRunner.java @@ -74,7 +74,7 @@ public class StandardDataFlowRunner extends DataFlowRunner { } PsiType returnType = method.getReturnType(); - return returnType != null && returnType.equalsToText(CommonClassNames.JAVA_LANG_VOID); + return returnType != null && (returnType == PsiType.VOID || returnType.equalsToText(CommonClassNames.JAVA_LANG_VOID)); } public void onInstructionProducesCCE(Instruction instruction) { diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/NullableVoidLambda.java b/java/java-tests/testData/inspection/dataFlow/fixture/NullableVoidLambda.java new file mode 100644 index 000000000000..1dfd1c8f9263 --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/fixture/NullableVoidLambda.java @@ -0,0 +1,12 @@ +import org.jetbrains.annotations.Nullable; + +class Example { + void foo() { + Runnable runnable = () -> bar(); + } + + @Nullable + String bar() { + return null; + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspection8Test.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspection8Test.java index 34b1c015678f..caca819a9245 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspection8Test.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspection8Test.java @@ -77,6 +77,7 @@ public class DataFlowInspection8Test extends LightCodeInsightFixtureTestCase { } public void testMethodReferenceOnNullable() { doTest(); } + public void testNullableVoidLambda() { doTest(); } public void testNullableForeachVariable() { setupCustomAnnotations();