apache/flink · error · IllegalArgumentException

The output size cannot be smaller than zero.

Error message

The output size cannot be smaller than zero.

What it means

Thrown by CompilerHints.setOutputSize(long) when the provided outputSize is negative. The default value is -1 (meaning 'unset'), and valid hints must be >= 0. Compiler hints help the optimizer estimate intermediate result sizes for plan selection; a negative size is nonsensical and rejected with an IllegalArgumentException.

Source

Thrown at flink-core/src/main/java/org/apache/flink/api/common/operators/CompilerHints.java:56

    private long outputCardinality = -1;

    private float avgOutputRecordSize = -1.0f;

    private float filterFactor = -1.0f;

    private Set<FieldSet> uniqueFields;

    // --------------------------------------------------------------------------------------------
    //  Basic Record Statistics
    // --------------------------------------------------------------------------------------------

    public long getOutputSize() {
        return outputSize;
    }

    public void setOutputSize(long outputSize) {
        if (outputSize < 0) {
            throw new IllegalArgumentException("The output size cannot be smaller than zero.");
        }

        this.outputSize = outputSize;
    }

    public long getOutputCardinality() {
        return this.outputCardinality;
    }

    public void setOutputCardinality(long outputCardinality) {
        if (outputCardinality < 0) {
            throw new IllegalArgumentException(
                    "The output cardinality cannot be smaller than zero.");
        }

        this.outputCardinality = outputCardinality;
    }

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Ensure the outputSize value is >= 0 before calling setOutputSize().
  2. If using -1 as a sentinel for 'unset', do not pass it to the setter; instead, simply omit the call (the default is already -1).
  3. Check the arithmetic that computes the hint value for underflow or sign errors.

Example fix

// before
hints.setOutputSize(estimatedSize - 1000);  // may be negative if estimatedSize < 1000
// after
long safeSize = Math.max(0, estimatedSize - 1000);
hints.setOutputSize(safeSize);
Defensive patterns

Strategy: validation

Validate before calling

// Guard against negative output size before setting
if (outputSize < 0) {
    throw new IllegalArgumentException("outputSize must be >= 0, got: " + outputSize);
}
hints.setOutputSize(outputSize);
// Or simply omit the call if the value is unknown (default -1 means 'unset')

Prevention

When it happens

Trigger: Calling setOutputSize() with a negative long value, often due to an arithmetic error in computing the hint value, or passing a default/uninitialized value that happens to be negative.

Common situations: An @Internal API rarely called directly by application developers. It is used in the optimizer and plan construction. A negative value may arise from a subtraction that underflows or from passing a sentinel (-1) that was meant to indicate 'unset' but is passed to the setter.

Related errors


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