jwtk/jjwt · error · java.lang.IllegalArgumentException

End index is less than start

Error message

End index is less than start ${start}: ${end}

What it means

Constructor guard of CharSequenceReader(subSequence, start, end): thrown when end is less than start. The reader intentionally allows indexes outside the character sequence's current bounds, but an inverted range (end < start) is an empty-contradiction the constructor rejects as a caller error.

Solutions

  1. Ensure end >= start at the call site, swapping or clamping values if the range is computed dynamically
  2. Fix the slicing logic that produced the inverted range (commonly a misplaced min/max or reversed arguments)
  3. If an empty range is intended, pass end equal to start
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at impl/src/main/java/io/jsonwebtoken/impl/io/CharSequenceReader.java:118 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of jwtk/jjwt@fb71496164 (2026-09-09). Data as JSON: /api/errors/2c41012f52bf7849. Report an issue: GitHub.

Appendix: source

Thrown at impl/src/main/java/io/jsonwebtoken/impl/io/CharSequenceReader.java:118

     * of the character sequence. This allows the character sequence to grow or shrink
     * in size without risking any {@link IndexOutOfBoundsException} to be thrown.
     * Instead, if the character sequence grows smaller than the start index, this
     * instance will act as if all characters have been read; if the character sequence
     * grows smaller than the end, this instance will use the actual character sequence
     * length.
     * </p>
     *
     * @param charSequence The character sequence, may be {@code null}
     * @param start        The start index in the character sequence, inclusive
     * @param end          The end index in the character sequence, exclusive
     * @throws IllegalArgumentException if the start index is negative, or if the end index is smaller than the start index
     */
    public CharSequenceReader(final CharSequence charSequence, final int start, final int end) {
        if (start < 0) {
            throw new IllegalArgumentException("Start index is less than zero: " + start);
        }
        if (end < start) {
            throw new IllegalArgumentException("End index is less than start " + start + ": " + end);
        }
        // Don't check the start and end indexes against the CharSequence,
        // to let it grow and shrink without breaking existing behavior.

        this.charSequence = charSequence != null ? charSequence : "";
        this.start = start;
        this.end = end;

        this.idx = start;
        this.mark = start;
    }

    /**
     * Close resets the file back to the start and removes any marked position.
     */
    @Override
    public void close() {
        idx = start;

View on GitHub (pinned to fb71496164)