{"record":{"id":"e14ea29b73bf7384","repo":"apache/flink","slug":"the-number-of-partitions-must-be-at-least-1","errorCode":null,"errorMessage":"The number of partitions must be at least 1.","messagePattern":"The number of partitions must be at least 1\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/util/LongValueSequenceIterator.java","lineNumber":105,"sourceCode":"    @Override\n    public LongValue next() {\n        if (current <= to) {\n            currentValue.setValue(current++);\n            return currentValue;\n        } else {\n            throw new NoSuchElementException();\n        }\n    }\n\n    @Override\n    public void remove() {\n        throw new UnsupportedOperationException();\n    }\n\n    @Override\n    public LongValueSequenceIterator[] split(int numPartitions) {\n        if (numPartitions < 1) {\n            throw new IllegalArgumentException(\"The number of partitions must be at least 1.\");\n        }\n\n        if (numPartitions == 1) {\n            return new LongValueSequenceIterator[] {new LongValueSequenceIterator(current, to)};\n        }\n\n        // here, numPartitions >= 2 !!!\n\n        long elementsPerSplit;\n\n        if (to - current + 1 >= 0) {\n            elementsPerSplit = (to - current + 1) / numPartitions;\n        } else {\n            // long overflow of the range.\n            // we compute based on half the distance, to prevent the overflow.\n            // in most cases it holds that: current < 0 and to > 0, except for: to == 0 and current\n            // == Long.MIN_VALUE\n            // the later needs a special case","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/util/LongValueSequenceIterator.java#L87-L123","documentation":"LongValueSequenceIterator implements the SplittableIterator contract via split(numPartitions), which divides the remaining [current, to] range into numPartitions sub-iterators for parallel reading. numPartitions < 1 is rejected with IllegalArgumentException because zero or negative partitions have no meaningful split semantics.","triggerScenarios":"Calling split(n) with n <= 0 — typically because the parallelism or split-count used to compute n was itself zero/unset (e.g. default int value from a missing config, or arithmetic that produced 0 for small inputs).","commonSituations":"Input format parallelism configured to 0 (implicit default when a field is never set); min(partitionCount, remainingElements) evaluating to 0 when the range is exhausted; downstream code deriving partition counts from collection sizes that are empty.","solutions":["Trace where numPartitions comes from and guarantee it is >= 1 before calling split (e.g. Math.max(1, computedPartitions)).","Fix the upstream config: set explicit parallelism / number of splits instead of relying on defaults that can be 0.","Guard the exhausted-range case: return an empty split array yourself when there is nothing left rather than passing 0 down.","Add a unit test asserting split(1) and split(2) work and split(0)/split(-1) throw."],"exampleFix":"// before\nLongValueSequenceIterator[] parts = iterator.split(numSplits); // numSplits may be 0\n\n// after\nint safeSplits = Math.max(1, numSplits);\nLongValueSequenceIterator[] parts = iterator.split(safeSplits);","handlingStrategy":"validation","validationCode":"int n = Math.max(1, numPartitions);\nLongValueSequenceIterator[] parts = iterator.split(n);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default partition counts to at least 1 in configuration","Guard against zero when deriving splits from collection sizes","Handle exhausted ranges before calling split"],"tags":["iterator","parallelism","validation","split"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}