fix dfa offset management when handling possible exceptions in finally

This commit is contained in:
peter
2013-09-30 14:49:48 +02:00
parent 25961fca03
commit cebb5b8936
3 changed files with 25 additions and 1 deletions
@@ -720,11 +720,12 @@ class ControlFlowAnalyzer extends JavaElementVisitor {
if (exceptionClass == null) return;
for (int i = myCatchStack.size() - 1; i >= 0; i--) {
CatchDescriptor cd = myCatchStack.get(i);
flushVariablesInsideTry(cd);
if (cd.isFinally()) {
flushVariablesInsideTry(cd);
addInstruction(new GosubInstruction(cd.getJumpOffset(this)));
}
else if (cd.getType().isAssignableFrom(exceptionClass)) { // Definite catch.
flushVariablesInsideTry(cd);
addGotoCatch(cd);
return;
}
@@ -733,6 +734,7 @@ class ControlFlowAnalyzer extends JavaElementVisitor {
pushUnknown();
final ConditionalGotoInstruction branch = new ConditionalGotoInstruction(null, false, null);
addInstruction(branch);
flushVariablesInsideTry(cd);
addGotoCatch(cd);
branch.setOffset(myCurrentFlow.getInstructionCount());
}
@@ -0,0 +1,21 @@
import java.io.*;
class Foo {
public void read() {
try {
final FileInputStream input = new FileInputStream(new File("foo"));
try {
}
finally {
input.close();
}
}
catch (FileNotFoundException ignored) {
}
catch (IOException e) {
}
}
}
@@ -68,6 +68,7 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
public void testTernaryInWhileNotComplex() throws Throwable { doTest(); }
public void testTryCatchInForNotComplex() throws Throwable { doTest(); }
public void testNestedTryInWhileNotComplex() throws Throwable { doTest(); }
public void testExceptionFromFinally() throws Throwable { doTest(); }
public void testFieldChangedBetweenSynchronizedBlocks() throws Throwable { doTest(); }
public void testGeneratedEquals() throws Throwable { doTest(); }