{"record":{"id":"6aca141003f816a5","repo":"apache/flink","slug":"buffer-size-must-be-at-least-2","errorCode":null,"errorMessage":"Buffer size must be at least 2.","messagePattern":"Buffer size must be at least 2\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/io/DelimitedInputFormat.java","lineNumber":267,"sourceCode":"    public int getLineLengthLimit() {\n        return lineLengthLimit;\n    }\n\n    public void setLineLengthLimit(int lineLengthLimit) {\n        if (lineLengthLimit < 1) {\n            throw new IllegalArgumentException(\"Line length limit must be at least 1.\");\n        }\n\n        this.lineLengthLimit = lineLengthLimit;\n    }\n\n    public int getBufferSize() {\n        return bufferSize;\n    }\n\n    public void setBufferSize(int bufferSize) {\n        if (bufferSize < 2) {\n            throw new IllegalArgumentException(\"Buffer size must be at least 2.\");\n        }\n\n        this.bufferSize = bufferSize;\n    }\n\n    public int getNumLineSamples() {\n        return numLineSamples;\n    }\n\n    public void setNumLineSamples(int numLineSamples) {\n        if (numLineSamples < 0) {\n            throw new IllegalArgumentException(\"Number of line samples must not be negative.\");\n        }\n        this.numLineSamples = numLineSamples;\n    }\n\n    // --------------------------------------------------------------------------------------------\n    //  User-defined behavior","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/io/DelimitedInputFormat.java#L249-L285","documentation":"DelimitedInputFormat's read buffer must hold at least the delimiter plus content to make scanning correct (the buffer is scanned for the delimiter across refill boundaries, and the wrap buffer needs headroom). A buffer of size 0 or 1 cannot reliably contain a multi-byte delimiter, so setBufferSize enforces a minimum of 2.","triggerScenarios":"Calling format.setBufferSize(0) or format.setBufferSize(1).","commonSituations":"Tuning the read buffer down too aggressively for memory savings; computing buffer size from a config that defaulted to 0; passing a value smaller than the delimiter length.","solutions":["Set bufferSize >= 2 (and strictly greater than the delimiter length — see also initBuffers guard, error 310).","Use a typical value like 1024 * 1024 (1 MB, the default) or at least a few KB.","Leave the default if you do not need to tune memory usage."],"exampleFix":"// before\nformat.setBufferSize(bufferBytes); // bufferBytes == 1 -> throws\n\n// after\nint bs = bufferBytes >= 2 ? bufferBytes : 4 * 1024;\nformat.setBufferSize(bs);","handlingStrategy":"validation","validationCode":"int bs = configuredBufferSize >= 2 ? configuredBufferSize : 1024 * 1024;\nformat.setBufferSize(bs);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure bufferSize >= 2 AND strictly greater than the delimiter length.","Do not shrink the buffer below a few KB for production.","Leave the default (1 MB) unless memory pressure demands otherwise."],"tags":["input-format","delimited","buffer-size","validation","illegal-argument"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}