IDEA-31555 Wrong warning: method invocation may produce a NullPointerException

This commit is contained in:
peter
2012-09-07 19:08:41 +02:00
parent 4b398c146d
commit b0428ec975
3 changed files with 41 additions and 1 deletions
@@ -685,7 +685,7 @@ class ControlFlowAnalyzer extends JavaElementVisitor {
private void addGotoCatch(CatchDescriptor cd) {
addInstruction(new PushInstruction(myFactory.getVarFactory().create(cd.getParameter(), false), null));
addInstruction(new SwapInstruction());
addInstruction(new AssignInstruction(null));
myCurrentFlow.addInstruction(new AssignInstruction(null));
addInstruction(new PopInstruction());
addInstruction(new GotoInstruction(cd.getJumpOffset()));
}
@@ -0,0 +1,39 @@
import java.io.IOException;
class TestIDEAWarn {
private Connection _connection;
public void warn() throws IOException {
try {
if (_connection != null) {
try {
_connection.commit();
} finally {
_connection.close();
_connection = null;
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public void warn2() throws IOException {
if (_connection == null) return;
try {
try {
_connection.commit();
} finally {
_connection.close();
_connection = null;
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
interface Connection {
void commit() throws IOException;
void close() throws IOException;
}
}
@@ -71,5 +71,6 @@ public class DataFlowInspectionFixtureTest extends JavaCodeInsightFixtureTestCas
public void testContinueFlushesLoopVariable() throws Throwable { doTest(); }
public void testEqualsNotNull() throws Throwable { doTest(); }
public void testVisitFinallyOnce() throws Throwable { doTest(); }
}