mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Assert.fail() in catch still executes finally (IDEA-81084)
This commit is contained in:
@@ -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)) {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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(); }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user