{"record":{"id":"2c3aacff67f1cd09","repo":"apache/flink","slug":"the-size-of-produced-records-must-be-positive","errorCode":null,"errorMessage":"The size of produced records must be positive.","messagePattern":"The size of produced records must be positive\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/operators/CompilerHints.java","lineNumber":81,"sourceCode":"        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\n    public float getAvgOutputRecordSize() {\n        return this.avgOutputRecordSize;\n    }\n\n    public void setAvgOutputRecordSize(float avgOutputRecordSize) {\n        if (avgOutputRecordSize <= 0) {\n            throw new IllegalArgumentException(\"The size of produced records must be positive.\");\n        }\n\n        this.avgOutputRecordSize = avgOutputRecordSize;\n    }\n\n    public float getFilterFactor() {\n        return filterFactor;\n    }\n\n    public void setFilterFactor(float filterFactor) {\n        if (filterFactor < 0) {\n            throw new IllegalArgumentException(\"The filter factor cannot be smaller than zero.\");\n        }\n\n        this.filterFactor = filterFactor;\n    }\n\n    // --------------------------------------------------------------------------------------------","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/operators/CompilerHints.java#L63-L99","documentation":"Thrown by CompilerHints.setAvgOutputRecordSize(float) when the provided value is <= 0. Unlike outputSize and outputCardinality which allow zero (an empty result is valid), the average record size must be strictly positive because a zero or negative record size is physically meaningless. The default is -1.0f (meaning 'unset'). This is an IllegalArgumentException.","triggerScenarios":"Calling setAvgOutputRecordSize() with 0 or a negative float. This can happen if the value is computed by dividing total size by cardinality where cardinality is 0 (producing 0 or NaN), or from an uninitialized value of 0.0f.","commonSituations":"An @Internal API used in optimizer internals. The average record size is often computed as outputSize / outputCardinality; if cardinality is 0 this yields 0.0 or Infinity, and passing that result to setAvgOutputRecordSize() triggers the exception. Also triggered by passing a computed hint where the source data has zero records.","solutions":["Ensure the average record size is strictly > 0 before calling setAvgOutputRecordSize().","Guard division: if computing avgOutputRecordSize = outputSize / cardinality, check that cardinality > 0 and the result > 0 before setting.","If the value is unknown or zero, omit the call (the default -1.0f signals 'unset')."],"exampleFix":"// before\nfloat avgSize = (float) totalBytes / recordCount;  // recordCount could be 0\nhints.setAvgOutputRecordSize(avgSize);\n// after\nif (recordCount > 0) {\n    float avgSize = (float) totalBytes / recordCount;\n    if (avgSize > 0) {\n        hints.setAvgOutputRecordSize(avgSize);\n    }\n}","handlingStrategy":"validation","validationCode":"// Guard against non-positive average record size before setting\nif (avgOutputRecordSize <= 0) {\n    throw new IllegalArgumentException(\"avgOutputRecordSize must be > 0, got: \" + avgOutputRecordSize);\n}\nhints.setAvgOutputRecordSize(avgOutputRecordSize);\n// Or omit the call if unknown (default -1.0f means 'unset')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Guard division: check cardinality > 0 before computing avgOutputRecordSize = size / cardinality.","Clamp to a small positive minimum (e.g., Math.max(0.001f, value)) if zero is possible.","Do not pass 0, -1, or NaN into setAvgOutputRecordSize()."],"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"}