apache/flink · error · InvalidProgramException

Operator producing the next version of the partial solution

Error message

Operator producing the next version of the partial solution (iteration result) is not set.

What it means

Thrown by BulkIterationBase.validate() as an InvalidProgramException when iterationResult is null — meaning setNextPartialSolution() was never called. The iteration body (the step function that produces the next version of the partial solution) is mandatory; without it the iteration has no way to progress.

Source

Thrown at flink-core/src/main/java/org/apache/flink/api/common/operators/base/BulkIterationBase.java:171

    public int getMaximumNumberOfIterations() {
        return this.numberOfIterations;
    }

    @Override
    public AggregatorRegistry getAggregators() {
        return this.aggregators;
    }

    /**
     * @throws InvalidProgramException
     */
    public void validate() throws InvalidProgramException {
        if (this.input == null) {
            throw new RuntimeException("Operator for initial partial solution is not set.");
        }
        if (this.iterationResult == null) {
            throw new InvalidProgramException(
                    "Operator producing the next version of the partial "
                            + "solution (iteration result) is not set.");
        }
        if (this.terminationCriterion == null && this.numberOfIterations <= 0) {
            throw new InvalidProgramException(
                    "No termination condition is set "
                            + "(neither fix number of iteration nor termination criterion).");
        }
    }

    /**
     * The BulkIteration meta operator cannot have broadcast inputs.
     *
     * @return An empty map.
     */
    public Map<String, Operator<?>> getBroadcastInputs() {
        return Collections.emptyMap();
    }

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Always call iteration.setNextPartialSolution(stepFunctionOperator) before validate() or execute().
  2. Ensure the step function operator (built from iteration.getPartialSolution()) is non-null and properly connected.
  3. Structure iteration construction to guarantee the step function is set in all code paths.

Example fix

// before
BulkIterationBase<MyType> iteration = new BulkIterationBase<>(operatorInfo, "my-iter");
iteration.setInput(dataSource);
iteration.setMaximumNumberOfIterations(10);
iteration.validate(); // throws: iterationResult not set

// after
BulkIterationBase<MyType> iteration = new BulkIterationBase<>(operatorInfo, "my-iter");
iteration.setInput(dataSource);
Operator<MyType> step = buildStep(iteration.getPartialSolution());
iteration.setNextPartialSolution(step);
iteration.setMaximumNumberOfIterations(10);
iteration.validate(); // ok
Defensive patterns

Strategy: validation

Validate before calling

void validateBeforeExecute(BulkIterationBase<?> iter) {
    if (iter.getNextPartialSolution() == null) {
        throw new IllegalStateException("Iteration step function (next partial solution) is not set.");
    }
    iter.validate();
}

Type guard

boolean hasStepFunction(BulkIterationBase<?> iter) {
    return iter.getNextPartialSolution() != null;
}

Try / catch

try {
    iteration.validate();
} catch (InvalidProgramException e) {
    if (e.getMessage().contains("iteration result")) {
        // build and set the step function
        Operator<?> step = buildStepFunction(iteration.getPartialSolution());
        iteration.setNextPartialSolution(step);
        iteration.validate();
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: Creating a BulkIterationBase, setting the input and iteration count, but forgetting to call setNextPartialSolution(stepFunction). Calling validate() before the step function is defined.

Common situations: Incomplete iteration construction in programmatic DataSet API usage. Conditional code paths that set the step function only in some branches. Refactoring that removes the setNextPartialSolution call without updating the validate flow.

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/c6b24eaa44833347. Report an issue: GitHub.