diff --git a/java/java-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java b/java/java-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java index ed0df551fe51..07b32f433dda 100644 --- a/java/java-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java +++ b/java/java-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java @@ -500,12 +500,16 @@ class ControlFlowAnalyzer extends JavaElementVisitor { addInstruction(new CheckReturnValueInstruction(statement)); } + returnCheckingFinally(); + finishElement(statement); + } + + private void returnCheckingFinally() { int finallyOffset = getFinallyOffset(); if (finallyOffset != NOT_FOUND) { addInstruction(new GosubInstruction(finallyOffset)); } addInstruction(new ReturnInstruction()); - finishElement(statement); } @Override public void visitSwitchLabelStatement(PsiSwitchLabelStatement statement) { @@ -1254,7 +1258,7 @@ class ControlFlowAnalyzer extends JavaElementVisitor { boolean testng = "org.testng.Assert".equals(className); if ("fail".equals(methodName)) { pushParameters(params, false, !testng); - addInstruction(new ReturnInstruction()); + returnCheckingFinally(); return true; } else if ("assertTrue".equals(methodName)) { @@ -1297,7 +1301,7 @@ class ControlFlowAnalyzer extends JavaElementVisitor { param.accept(this); addInstruction(new PopInstruction()); } - addInstruction(new ReturnInstruction()); + returnCheckingFinally(); return true; } else if ("assertTrue".equals(methodName)) { diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/AssertFailInCatch.java b/java/java-tests/testData/inspection/dataFlow/fixture/AssertFailInCatch.java new file mode 100644 index 000000000000..93fcf6d5c2d2 --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/fixture/AssertFailInCatch.java @@ -0,0 +1,24 @@ +import org.jetbrains.annotations.NotNull; +import org.junit.Assert; + +class Test { + + public static void foo() { + String result = null; + try { + result = createString(); + } + catch (Exception e) { + Assert.fail(); + } + finally { + if (result == null) { + System.out.println("Analysis failed!"); + } + } + } + + private static @NotNull String createString() { + throw new NullPointerException(); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java index e4f0751aac17..4a05f32603b3 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java @@ -91,6 +91,12 @@ public class DataFlowInspectionFixtureTest extends JavaCodeInsightFixtureTestCas public void testReturningNullFromVoidMethod() throws Throwable { doTest(); } public void testCatchRuntimeException() throws Throwable { doTest(); } + + public void testAssertFailInCatch() throws Throwable { + myFixture.addClass("package org.junit; public class Assert { public static void fail() {}}"); + doTest(); + } + public void testPreserveNullableOnUncheckedCast() throws Throwable { doTest(); } }