[java-dfa] Copy state for catch (regression after AIOOBE handling)

Fixes IDEA-349343 Exceptions during DFA Dataflow interpretation error (wasForciblyMerged = false), throwable=java.lang.IllegalStateException: Stack for instruction 72 increased by 13; it's likely that IR was built incorrectly

GitOrigin-RevId: 2ebeeb9b58d6daa94ff885d20c606cae6e5391bb
This commit is contained in:
Tagir Valeev
2024-03-18 15:33:49 +00:00
committed by intellij-monorepo-bot
parent e07cedf5b3
commit 6a98eecf0f
4 changed files with 14 additions and 2 deletions
@@ -50,7 +50,7 @@ public class ArrayAccessInstruction extends ExpressionPushingInstruction {
DfaValue array = stateBefore.pop();
List<DfaInstructionState> finalStates = new ArrayList<>();
if (myOutOfBoundsTransfer != null) {
finalStates.addAll(IndexOutOfBoundsProblem.dispatchTransfer(interpreter, stateBefore, myOutOfBoundsTransfer));
finalStates.addAll(IndexOutOfBoundsProblem.dispatchTransfer(interpreter, stateBefore.createCopy(), myOutOfBoundsTransfer));
}
DfaInstructionState[] states = myProblem.processOutOfBounds(interpreter, stateBefore, index, array, myOutOfBoundsTransfer);
if (states != null) return states;
@@ -56,7 +56,7 @@ public class ArrayStoreInstruction extends ExpressionPushingInstruction {
DfaValue array = stateBefore.pop();
List<DfaInstructionState> finalStates = new ArrayList<>();
if (myOutOfBoundsTransfer != null) {
finalStates.addAll(IndexOutOfBoundsProblem.dispatchTransfer(interpreter, stateBefore, myOutOfBoundsTransfer));
finalStates.addAll(IndexOutOfBoundsProblem.dispatchTransfer(interpreter, stateBefore.createCopy(), myOutOfBoundsTransfer));
}
DfaInstructionState[] states =
myIndexProblem.processOutOfBounds(interpreter, stateBefore, index, array, myOutOfBoundsTransfer);
@@ -0,0 +1,11 @@
class Scratch {
public static void main(String[] files) {
try {
System.out.println(files[0]);
files[1] = "hello";
}
catch (RuntimeException e) {
System.out.println(e);
}
}
}
@@ -579,6 +579,7 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase {
public void testGetterOfNullableFieldIsNotNull() { doTest(); }
public void testArrayStoreProblems() { doTest(); }
public void testArrayAccessInTry() { doTest(); }
public void testNestedScopeComplexity() { doTest(); }