{"record":{"id":"7f33301702ad6053","repo":"apache/flink","slug":"number-of-line-samples-must-not-be-negative","errorCode":null,"errorMessage":"Number of line samples must not be negative.","messagePattern":"Number of line samples must not be negative\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/io/DelimitedInputFormat.java","lineNumber":279,"sourceCode":"    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\n    // --------------------------------------------------------------------------------------------\n\n    /**\n     * This function parses the given byte array which represents a serialized record. The function\n     * returns a valid record or throws an IOException.\n     *\n     * @param reuse An optionally reusable object.\n     * @param bytes Binary data of serialized records.\n     * @param offset The offset where to start to read the record data.\n     * @param numBytes The number of bytes that can be read starting at the offset position.\n     * @return Returns the read record if it was successfully deserialized.\n     * @throws IOException if the record could not be read.","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/io/DelimitedInputFormat.java#L261-L297","documentation":"DelimitedInputFormat uses numLineSamples to decide how many records to sample when computing input statistics for split sizing. 0 means 'disable sampling' (a valid value); negative is invalid. setNumLineSamples rejects negatives to distinguish 'disabled' (0) from 'misconfigured'.","triggerScenarios":"Calling format.setNumLineSamples(-1) or any negative integer.","commonSituations":"Passing -1 intending 'unlimited' (the format does not support that); computing the sample count from a subtraction that underflows; reading the value from a config that uses -1 as 'undefined'.","solutions":["Pass 0 to disable sampling, or a positive count (e.g. format.setNumLineSamples(10)).","Coerce negative inputs to 0 (disable) before calling setNumLineSamples.","Use the default (NUM_SAMPLES_UNDEFINED is resolved at getStatistics time, not here)."],"exampleFix":"// before\nformat.setNumLineSamples(sampleCount); // sampleCount == -1 -> throws\n\n// after\nint n = sampleCount >= 0 ? sampleCount : 0;\nformat.setNumLineSamples(n);","handlingStrategy":"validation","validationCode":"int n = configuredNumLineSamples >= 0 ? configuredNumLineSamples : 0;\nformat.setNumLineSamples(n);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use 0 to disable sampling; positive for explicit count.","Remember the format has no '-1 means unlimited' convention here.","Coerce negative config values to 0 before calling setNumLineSamples."],"tags":["input-format","delimited","sampling","validation","illegal-argument"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}