jwtk/jjwt · error · java.lang.IndexOutOfBoundsException

Array Size=${array.length}, offset=${offset}, length=${lengt

Error message

Array Size=${array.length}, offset=${offset}, length=${length}

What it means

Bounds guard in CharSequenceReader.read(char[], offset, length): thrown via Objects/validator checks when the destination array is null or offset/length are negative or exceed the array's size. The message echoes the array length, offset, and length so the caller can identify which argument violated read(char[], int, int)'s contract.

Source

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

    }

    /**
     * Read the specified number of characters into the array.
     *
     * @param array  The array to store the characters in
     * @param offset The starting position in the array to store
     * @param length The maximum number of characters to read
     * @return The number of characters read or -1 if there are
     * no more
     */
    @Override
    public int read(final char[] array, final int offset, final int length) {
        if (idx >= end()) {
            return Streams.EOF;
        }
        Objects.requireNonNull(array, "array");
        if (length < 0 || offset < 0 || offset + length > array.length) {
            throw new IndexOutOfBoundsException("Array Size=" + array.length +
                    ", offset=" + offset + ", length=" + length);
        }

        if (charSequence instanceof String) {
            final int count = Math.min(length, end() - idx);
            ((String) charSequence).getChars(idx, idx + count, array, offset);
            idx += count;
            return count;
        }
        if (charSequence instanceof StringBuilder) {
            final int count = Math.min(length, end() - idx);
            ((StringBuilder) charSequence).getChars(idx, idx + count, array, offset);
            idx += count;
            return count;
        }
        if (charSequence instanceof StringBuffer) {
            final int count = Math.min(length, end() - idx);
            ((StringBuffer) charSequence).getChars(idx, idx + count, array, offset);

View on GitHub (pinned to fb71496164)

Solutions

  1. Ensure 0 <= offset and 0 <= length and offset + length <= array.length before calling read
  2. Pass a non-null, adequately sized destination buffer
  3. Fix the buffer-size computation (e.g. use Math.min(requested, array.length - offset))
Defensive patterns

Strategy: validation

When it happens

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