jwtk/jjwt · error · java.lang.IllegalArgumentException

Number of characters to skip is less than zero

Error message

Number of characters to skip is less than zero: ${n}

What it means

Guard in CharSequenceReader.skip: thrown when the requested skip count n is negative. Java's Reader.skip contract disallows negative amounts, so this is a caller programming-error signal, unrelated to the reader's position or the underlying character sequence.

Solutions

  1. Validate the skip amount before calling (skip only when n > 0, or clamp with Math.max(0, n))
  2. Fix the computation that produced the negative count (frequently an unguarded subtraction)
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at impl/src/main/java/io/jsonwebtoken/impl/io/CharSequenceReader.java:266 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/7448d2c9e814b2df. Report an issue: GitHub.

Appendix: source

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

    /**
     * Reset the reader to the last marked position (or the beginning if
     * mark has not been called).
     */
    @Override
    public void reset() {
        idx = mark;
    }

    /**
     * Skip the specified number of characters.
     *
     * @param n The number of characters to skip
     * @return The actual number of characters skipped
     */
    @Override
    public long skip(final long n) {
        if (n < 0) {
            throw new IllegalArgumentException("Number of characters to skip is less than zero: " + n);
        }
        if (idx >= end()) {
            return 0;
        }
        final int dest = (int) Math.min(end(), idx + n);
        final int count = dest - idx;
        idx = dest;
        return count;
    }

    /**
     * Returns the index in the character sequence to start reading from, taking into account its length.
     *
     * @return The start index in the character sequence (inclusive).
     */
    private int start() {
        return Math.min(charSequence.length(), start);
    }

View on GitHub (pinned to fb71496164)