{"record":{"id":"6030c8d9fbcfe3e2","repo":"apache/flink","slug":"the-iteration-has-no-next-partial-solution-defi","errorCode":null,"errorMessage":"The iteration {} has no next partial solution defined (is not closed).","messagePattern":"The iteration (.+?) has no next partial solution defined \\(is not closed\\)\\.","errorType":"validation","errorClass":"InvalidProgramException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/operators/CollectionExecutor.java","lineNumber":331,"sourceCode":"        } else {\n            ctx = null;\n        }\n\n        return typedOp.executeOnCollections(inputData1, inputData2, ctx, executionConfig);\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    private <T> List<T> executeBulkIteration(BulkIterationBase<?> iteration, JobInfo jobInfo)\n            throws Exception {\n        Operator<?> inputOp = iteration.getInput();\n        if (inputOp == null) {\n            throw new InvalidProgramException(\n                    \"The iteration \"\n                            + iteration.getName()\n                            + \" has no input (initial partial solution).\");\n        }\n        if (iteration.getNextPartialSolution() == null) {\n            throw new InvalidProgramException(\n                    \"The iteration \"\n                            + iteration.getName()\n                            + \" has no next partial solution defined (is not closed).\");\n        }\n\n        List<T> inputData = (List<T>) execute(inputOp, jobInfo);\n\n        // get the operators that are iterative\n        Set<Operator<?>> dynamics = new LinkedHashSet<Operator<?>>();\n        DynamicPathCollector dynCollector = new DynamicPathCollector(dynamics);\n        iteration.getNextPartialSolution().accept(dynCollector);\n        if (iteration.getTerminationCriterion() != null) {\n            iteration.getTerminationCriterion().accept(dynCollector);\n        }\n\n        // register the aggregators\n        for (AggregatorWithName<?> a : iteration.getAggregators().getAllRegisteredAggregators()) {\n            aggregators.put(a.getName(), a.getAggregator());","sourceCodeStart":313,"sourceCodeEnd":349,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/operators/CollectionExecutor.java#L313-L349","documentation":"Thrown by CollectionExecutor.executeBulkIteration() when iteration.getNextPartialSolution() returns null. The next partial solution is the operator that produces the updated value for the next iteration step; if it is null, the iteration was never 'closed' — the developer forgot to call closeWith() to define the step function's output. This is an InvalidProgramException.","triggerScenarios":"Creating an IterativeDataSet via dataSet.iterate(n) but never calling iterate.closeWith(stepResult). The iteration loop body is defined but never terminated, so getNextPartialSolution() remains null.","commonSituations":"A developer writes an iterative algorithm, defines the step function (the transformation applied each iteration), but forgets to close the loop with closeWith(). This is a common mistake when first learning the Flink iteration API. The code compiles but fails at execution time.","solutions":["Call iter.closeWith(nextPartialSolution) to close the iteration and define the step function's output.","Verify the closeWith() call receives the correct DataSet that represents the result of one iteration step.","Review the iteration structure: iterate() → define step body → closeWith(stepResult) → use the returned DataSet."],"exampleFix":"// before — iteration never closed\nIterativeDataSet<Long> iter = initialDataSet.iterate(100);\nDataSet<Long> step = iter.map(x -> x / 2);\n// missing: DataSet<Long> result = iter.closeWith(step);\nresult.writeAsText(path);\n// after\nIterativeDataSet<Long> iter = initialDataSet.iterate(100);\nDataSet<Long> step = iter.map(x -> x / 2);\nDataSet<Long> result = iter.closeWith(step);\nresult.writeAsText(path);","handlingStrategy":"validation","validationCode":"// Ensure bulk iteration is closed\nIterativeDataSet<Long> iter = initialDataSet.iterate(100);\nDataSet<Long> step = iter.map(fn);\nif (step == null) {\n    throw new IllegalStateException(\"Step function result is null\");\n}\nDataSet<Long> result = iter.closeWith(step); // required call","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always call closeWith(stepResult) on IterativeDataSet to close the loop.","Review the iteration pattern: iterate() → step body → closeWith(stepResult).","Static analysis: grep for .iterate( that is not followed by .closeWith(."],"tags":["iteration","bulk-iteration","plan-validation","closewith","flink-core"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}