{"record":{"id":"12a634c453018df7","repo":"jwtk/jjwt","slug":"start-index-is-less-than-zero-start","errorCode":null,"errorMessage":"Start index is less than zero: ${start}","messagePattern":"Start index is less than zero: (.+?)","errorType":"validation","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"impl/src/main/java/io/jsonwebtoken/impl/io/CharSequenceReader.java","lineNumber":115,"sourceCode":"     * Constructs a new instance with a portion of the specified character sequence.\n     * <p>\n     * The start and end indexes are not strictly enforced to be within the bounds\n     * of the character sequence. This allows the character sequence to grow or shrink\n     * in size without risking any {@link IndexOutOfBoundsException} to be thrown.\n     * Instead, if the character sequence grows smaller than the start index, this\n     * instance will act as if all characters have been read; if the character sequence\n     * grows smaller than the end, this instance will use the actual character sequence\n     * length.\n     * </p>\n     *\n     * @param charSequence The character sequence, may be {@code null}\n     * @param start        The start index in the character sequence, inclusive\n     * @param end          The end index in the character sequence, exclusive\n     * @throws IllegalArgumentException if the start index is negative, or if the end index is smaller than the start index\n     */\n    public CharSequenceReader(final CharSequence charSequence, final int start, final int end) {\n        if (start < 0) {\n            throw new IllegalArgumentException(\"Start index is less than zero: \" + start);\n        }\n        if (end < start) {\n            throw new IllegalArgumentException(\"End index is less than start \" + start + \": \" + end);\n        }\n        // Don't check the start and end indexes against the CharSequence,\n        // to let it grow and shrink without breaking existing behavior.\n\n        this.charSequence = charSequence != null ? charSequence : \"\";\n        this.start = start;\n        this.end = end;\n\n        this.idx = start;\n        this.mark = start;\n    }\n\n    /**\n     * Close resets the file back to the start and removes any marked position.\n     */","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/jwtk/jjwt/blob/fb71496164c71442d08adec4571d9616ed5e1b8d/impl/src/main/java/io/jsonwebtoken/impl/io/CharSequenceReader.java#L97-L133","documentation":"Constructor guard of CharSequenceReader(subSequence, start, end): thrown when the requested start index is negative. The reader tolerates indexes beyond the sequence's bounds (it treats them as EOF as the sequence changes), but a negative start is nonsensical and rejected up front as a caller programming error.","triggerScenarios":"Thrown at impl/src/main/java/io/jsonwebtoken/impl/io/CharSequenceReader.java:115 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Compute start from a non-negative source (e.g. clamp with Math.max(0, startIndex)) before constructing the reader","Fix the offset calculation that produced the negative index (often an off-by-one or an unguarded subtraction)"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fb71496164c71442d08adec4571d9616ed5e1b8d","analyzedAt":"2026-09-09T00:33:09.982Z","contentChangedAt":"2026-09-09T00:33:09.982Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}