{"record":{"id":"ee22f1af4e875adf","repo":"apache/flink","slug":"the-number-of-partitions-must-be-at-least-1-ee22f1","errorCode":null,"errorMessage":"The number of partitions must be at least 1.","messagePattern":"The number of partitions must be at least 1\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/util/NumberSequenceIterator.java","lineNumber":100,"sourceCode":"\n    @Override\n    public Long next() {\n        if (current <= to) {\n            return current++;\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 NumberSequenceIterator[] 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 NumberSequenceIterator[] {new NumberSequenceIterator(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":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/util/NumberSequenceIterator.java#L82-L118","documentation":"NumberSequenceIterator.split(numPartitions) requires at least one partition; values < 1 throw IllegalArgumentException. The method implements the splittable-parallel-source contract and is called by the runtime with the source parallelism. A zero/negative parallelism reaching this point means upstream config or logic is wrong.","triggerScenarios":"Calling split(0) or split(-1), e.g. generateSequence(...).setParallelism(0) flowing into source splitting; passing an unconfigured int that defaults to 0.","commonSituations":"Parallelism read from a missing config option defaulting to 0; dynamic parallelism computed as max(0, demand) and not clamped to >= 1; test harnesses invoking split directly.","solutions":["Ensure parallelism for the sequence source is at least 1.","Clamp computed parallelism: Math.max(1, requestedParallelism).","Check the config key feeding the parallelism (missing options can yield 0 in custom code)."],"exampleFix":"// before\nint par = config.get(\"source.parallelism\", 0);\nNumberSequenceIterator[] parts = new NumberSequenceIterator(1, 1000).split(par);\n\n// after\nint par = Math.max(1, config.get(\"source.parallelism\", 1));\nNumberSequenceIterator[] parts = new NumberSequenceIterator(1, 1000).split(par);","handlingStrategy":"validation","validationCode":"int safePar = Math.max(1, requestedParallelism);\nNumberSequenceIterator[] parts = source.split(safePar);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp parallelism to >= 1 wherever it is computed dynamically.","Default parallelism config keys to 1, never 0."],"tags":["iterator","parallelism","validation","flink-core"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}