{"record":{"id":"553d20eeaca7ab4f","repo":"apache/flink","slug":"the-output-size-cannot-be-smaller-than-zero","errorCode":null,"errorMessage":"The output size cannot be smaller than zero.","messagePattern":"The output size cannot be smaller than zero\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/operators/CompilerHints.java","lineNumber":56,"sourceCode":"    private long outputCardinality = -1;\n\n    private float avgOutputRecordSize = -1.0f;\n\n    private float filterFactor = -1.0f;\n\n    private Set<FieldSet> uniqueFields;\n\n    // --------------------------------------------------------------------------------------------\n    //  Basic Record Statistics\n    // --------------------------------------------------------------------------------------------\n\n    public long getOutputSize() {\n        return outputSize;\n    }\n\n    public void setOutputSize(long outputSize) {\n        if (outputSize < 0) {\n            throw new IllegalArgumentException(\"The output size cannot be smaller than zero.\");\n        }\n\n        this.outputSize = outputSize;\n    }\n\n    public long getOutputCardinality() {\n        return this.outputCardinality;\n    }\n\n    public void setOutputCardinality(long outputCardinality) {\n        if (outputCardinality < 0) {\n            throw new IllegalArgumentException(\n                    \"The output cardinality cannot be smaller than zero.\");\n        }\n\n        this.outputCardinality = outputCardinality;\n    }\n","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/operators/CompilerHints.java#L38-L74","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the outputSize value is >= 0 before calling setOutputSize().","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).","Check the arithmetic that computes the hint value for underflow or sign errors."],"exampleFix":"// before\nhints.setOutputSize(estimatedSize - 1000);  // may be negative if estimatedSize < 1000\n// after\nlong safeSize = Math.max(0, estimatedSize - 1000);\nhints.setOutputSize(safeSize);","handlingStrategy":"validation","validationCode":"// Guard against negative output size before setting\nif (outputSize < 0) {\n    throw new IllegalArgumentException(\"outputSize must be >= 0, got: \" + outputSize);\n}\nhints.setOutputSize(outputSize);\n// Or simply omit the call if the value is unknown (default -1 means 'unset')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure computed hint values are clamped to >= 0 with Math.max(0, value).","Do not pass the -1 sentinel (default 'unset') into the setter.","Guard arithmetic that may underflow before passing to setOutputSize()."],"tags":["compiler-hints","validation","argument-check","flink-core"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}