Code review comment: Why not just assign to `snapshot` within the try-block?

Code under review:
private OperatorSubtaskState prepareState() throws Exception {
        char[] fatArray = new char[wordLen];
        Random random = new Random(0);
        for (int i = 0; i < fatArray.length; i++) {
            fatArray[i] = (char) random.nextInt();
        }

        KeySelector<String, String> keySelector = value -> value;
        KeyedOneInputStreamOperatorTestHarness<String, String, Integer>[] harnessBefore =
                new KeyedOneInputStreamOperatorTestHarness[parallelismBefore];
        OperatorSubtaskState snapshot = null;

        try (KeyedOneInputStreamOperatorTestHarness<String, String, Integer> harness =
                getTestHarness(keySelector, maxParallelism, 1, 0)) {
            harness.setStateBackend(stateBackend);
            harness.open();
            for (int i = 0; i < numberElements; i++) {
                harness.processElement(new StreamRecord<>(covertToString(i, fatArray), 0));
            }
            snapshot = harness.snapshot(0, 1);

            OperatorSubtaskState[] subtaskStates = new OperatorSubtaskState[parallelismBefore];
            for (int i = 0; i < parallelismBefore; i++) {
                OperatorSubtaskState subtaskState =
                        AbstractStreamOperatorTestHarness.repartitionOperatorState(
                                snapshot, maxParallelism, 1, parallelismBefore, i);

                harnessBefore[i] =
                        getTestHarness(keySelector, maxParallelism, parallelismBefore, i);
                harnessBefore[i].setStateBackend(stateBackend);
                harnessBefore[i].setup();
                harnessBefore[i].initializeState(subtaskState);
                harnessBefore[i].open();
                subtaskStates[i] = harnessBefore[i].snapshot(1, 2);
            }
            return AbstractStreamOperatorTestHarness.repackageState(subtaskStates);
        } finally {
            closeHarness(harnessBefore);
        }
    }

Line commented on: OperatorSubtaskState snapshot = null;

Revised code:
private OperatorSubtaskState prepareState() throws Exception {

        KeyedOneInputStreamOperatorTestHarness<KEY, KEY, Void>[] harnessBefore =
                new KeyedOneInputStreamOperatorTestHarness[parallelismBefore];
        try {
            for (int i = 0; i < parallelismBefore; i++) {

                harnessBefore[i] = getTestHarness(x -> x, maxParallelism, parallelismBefore, i);
                harnessBefore[i].setStateBackend(stateBackend);
                harnessBefore[i].setup();
                harnessBefore[i].open();
            }

            Iterator<StreamRecord<KEY>> iterator = streamRecordGenerator.generate();
            while (iterator.hasNext()) {
                StreamRecord<KEY> next = iterator.next();
                int keyGroupIndex =
                        KeyGroupRangeAssignment.assignToKeyGroup(next.getValue(), maxParallelism);
                int subtaskIndex =
                        KeyGroupRangeAssignment.computeOperatorIndexForKeyGroup(
                                maxParallelism, parallelismBefore, keyGroupIndex);
                harnessBefore[subtaskIndex].processElement(next);
            }

            OperatorSubtaskState[] subtaskState = new OperatorSubtaskState[parallelismBefore];

            for (int i = 0; i < parallelismBefore; i++) {
                subtaskState[i] = harnessBefore[i].snapshot(0, 1);
            }
            return AbstractStreamOperatorTestHarness.repackageState(subtaskState);
        } finally {
            closeHarnessArray(harnessBefore);
        }
    }