diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/java/inst/ArrayAccessInstruction.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/java/inst/ArrayAccessInstruction.java index ddedc34bad50..50a159ada658 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/java/inst/ArrayAccessInstruction.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/java/inst/ArrayAccessInstruction.java @@ -50,7 +50,7 @@ public class ArrayAccessInstruction extends ExpressionPushingInstruction { DfaValue array = stateBefore.pop(); List 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; diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/java/inst/ArrayStoreInstruction.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/java/inst/ArrayStoreInstruction.java index 865beb5cbb3d..1c4f0d175019 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/java/inst/ArrayStoreInstruction.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/java/inst/ArrayStoreInstruction.java @@ -56,7 +56,7 @@ public class ArrayStoreInstruction extends ExpressionPushingInstruction { DfaValue array = stateBefore.pop(); List 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); diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/ArrayAccessInTry.java b/java/java-tests/testData/inspection/dataFlow/fixture/ArrayAccessInTry.java new file mode 100644 index 000000000000..17b52e09a801 --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/fixture/ArrayAccessInTry.java @@ -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); + } + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspectionTest.java b/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspectionTest.java index cc97af92d301..08588cdd6135 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspectionTest.java @@ -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(); }