{"record":{"id":"f6d002102c0842c9","repo":"ReactiveX/RxJava","slug":"integer-overflow-f6d002","errorCode":null,"errorMessage":"Integer overflow","messagePattern":"Integer overflow","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/reactivex/rxjava4/core/Streamable.java","lineNumber":496,"sourceCode":"     * @param start the start element\n     * @param count the number of elements to emit\n     * @return the new {@code Streamable} instance\n     * @throws IllegalArgumentException if {@code count} is negative\n     */\n    @CheckReturnValue\n    @NonNull\n    static Streamable<Integer> range(int start, int count) {\n        if (count < 0) {\n            throw new IllegalArgumentException(\"count >= 0 required but it was \" + count);\n        } else\n        if (count == 0) {\n            return empty();\n        } else\n        if (count == 1) {\n            return just(start);\n        } else\n        if ((long)start + (count - 1) > Integer.MAX_VALUE) {\n            throw new IllegalArgumentException(\"Integer overflow\");\n        }\n        return RxJavaPlugins.onAssembly(new StreamableRange(start, count));\n    }\n\n    /**\n     * Emits elements from start up to start + count exclusive.\n     * @param start the start element\n     * @param count the number of elements to emit\n     * @return the new {@code Streamable} instance\n     * @throws IllegalArgumentException if {@code count} is negative\n     */\n    @CheckReturnValue\n    @NonNull\n    static Streamable<Long> rangeLong(long start, long count) {\n        if (count < 0) {\n            throw new IllegalArgumentException(\"count >= 0 required but it was \" + count);\n        }\n","sourceCodeStart":478,"sourceCodeEnd":514,"githubUrl":"https://github.com/ReactiveX/RxJava/blob/a8ab5356143f37a8f1dd6d76c79191bec5fa343b/src/main/java/io/reactivex/rxjava4/core/Streamable.java#L478-L514","documentation":"Thrown by Streamable.range when the inclusive endpoint start + (count - 1) exceeds Integer.MAX_VALUE. Because the operator emits ints, the range must fit in the int domain; the library casts to long to detect overflow safely and fails fast rather than wrapping.","triggerScenarios":"Calling Streamable.range(start, count) where (long)start + (count - 1) > Integer.MAX_VALUE. Happens with high positive start values plus a large count.","commonSituations":"Generating ranges that cross the top of the int domain; counters near Integer.MAX_VALUE; unvalidated computed ranges.","solutions":["Reduce start and/or count so the inclusive end stays <= Integer.MAX_VALUE.","Validate up front: boolean overflow = (long)start + (count - 1) > Integer.MAX_VALUE.","Switch to Streamable.rangeLong if you need the long domain."],"exampleFix":"// before\nStreamable.range(Integer.MAX_VALUE - 10, 100);\n\n// after\n// option A: clamp into the int domain\nint start = Integer.MAX_VALUE - 10;\nint count = Math.min(100, Integer.MAX_VALUE - start + 1);\nStreamable.range(start, count);\n// option B: move to the long domain\nStreamable.rangeLong((long)Integer.MAX_VALUE - 10, 100L);","handlingStrategy":"validation","validationCode":"if ((long)start + (count - 1) > Integer.MAX_VALUE) {\n    count = Integer.MAX_VALUE - start + 1;\n}","typeGuard":null,"tryCatchPattern":"try {\n    return Streamable.range(start, count);\n} catch (IllegalArgumentException e) {\n    return Streamable.rangeLong((long)start, (long)count);\n}","preventionTips":["Cast to long when validating the inclusive endpoint: (long)start + (count - 1).","Avoid seeding start near Integer.MAX_VALUE.","Prefer rangeLong when magnitudes may exceed the int domain."],"tags":["rxjava","streamable","range","overflow","arithmetic"],"backgroundTag":null,"analyzedSha":"a8ab5356143f37a8f1dd6d76c79191bec5fa343b","analyzedAt":"2026-08-13T23:25:30.069Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}