{"record":{"id":"67dacb1213e9ac3e","repo":"apache/flink","slug":"the-to-value-must-not-be-smaller-than-the-from","errorCode":null,"errorMessage":"The 'to' value must not be smaller than the 'from' value.","messagePattern":"The 'to' value must not be smaller than the 'from' value\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/util/LongValueSequenceIterator.java","lineNumber":54,"sourceCode":"    /** The last number returned by the iterator. */\n    private final long to;\n\n    /** The next number to be returned. */\n    private long current;\n\n    /** The next value to be returned. */\n    private LongValue currentValue = new LongValue();\n\n    /**\n     * Creates a new splittable iterator, returning the range [from, to]. Both boundaries of the\n     * interval are inclusive.\n     *\n     * @param from The first number returned by the iterator.\n     * @param to The last number returned by the iterator.\n     */\n    public LongValueSequenceIterator(long from, long to) {\n        if (from > to) {\n            throw new IllegalArgumentException(\n                    \"The 'to' value must not be smaller than the 'from' value.\");\n        }\n\n        this.current = from;\n        this.to = to;\n    }\n\n    /**\n     * Internal constructor to allow for empty iterators.\n     *\n     * @param from The first number returned by the iterator.\n     * @param to The last number returned by the iterator.\n     * @param unused A dummy parameter to disambiguate the constructor.\n     */\n    private LongValueSequenceIterator(long from, long to, boolean unused) {\n        this.current = from;\n        this.to = to;\n    }","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/util/LongValueSequenceIterator.java#L36-L72","documentation":"LongValueSequenceIterator generates the inclusive range [from, to] of longs. The constructor enforces from <= to and throws IllegalArgumentException otherwise, because an empty/reversed range is not representable by this iterator (an internal constructor exists for empty iterators).","triggerScenarios":"Constructing new LongValueSequenceIterator(from, to) with from > to — e.g. computing bounds from dynamic input where the start overtook the end, or off-by-one math producing start = end + 1.","commonSituations":"Generating test/benchmark data ranges from configuration values (e.g. datagen-style sequence sources) where the user sets 'from' greater than 'to'; range arithmetic where the upper bound minus count undershoots the lower bound.","solutions":["Check and correct the range parameters: ensure from <= to before constructing (swap or clamp as your semantics require).","Validate user-supplied range configs at parse time with a clear error message naming both values.","If an empty range is legitimate in your flow, skip iterator creation when from > to instead of constructing it.","Add boundary unit tests for from == to (single element) and from == to + 1 to catch regressions."],"exampleFix":"// before\nnew LongValueSequenceIterator(start, end); // start=10, end=5 -> IAE\n\n// after\nif (start > end) {\n    throw new IllegalArgumentException(\"start (\" + start + \") must be <= end (\" + end + \")\");\n}\nreturn new LongValueSequenceIterator(start, end);","handlingStrategy":"validation","validationCode":"if (from > to) {\n    throw new IllegalArgumentException(\"from (\" + from + \") must be <= to (\" + to + \")\");\n}\nreturn new LongValueSequenceIterator(from, to);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate range bounds at config-parse time","Skip iterator construction for empty ranges","Unit-test from == to and from == to + 1 boundaries"],"tags":["iterator","range","validation","test-data"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}