ControlFlowAnalyzer: pop result of resource expression (Java 9)

If it's not popped, it causes misbalanced stack which may lead to exceptions/strange behavior in data flow analysis.
This commit is contained in:
Tagir Valeev
2017-10-09 15:59:45 +07:00
parent 28e3a28f8e
commit 59526abd92
3 changed files with 22 additions and 0 deletions
@@ -972,6 +972,7 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
}
else if (resource instanceof PsiResourceExpression) {
((PsiResourceExpression)resource).getExpression().accept(this);
addInstruction(new PopInstruction());
}
final List<PsiClassType> closerExceptions = ExceptionUtil.getCloserExceptions(resource);
@@ -0,0 +1,19 @@
class Test {
public void closeable(AutoCloseable y) {
try(<error descr="Resource references are not supported at language level '1.7'">y</error>) {
System.out.println("Hello");
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
public void incompleteCode(AutoCloseable y) {
try(<error descr="Resource references are not supported at language level '1.7'">y</error><error descr="')' expected"> </error>{
System.out.println("Hello");
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
}
@@ -546,4 +546,6 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase {
public void testGetterOfNullableFieldIsNotAnnotated() { doTest(); }
public void testGetterOfNullableFieldIsNotNull() { doTest(); }
public void testTryWithResourceExpressions() { doTest(); }
}