jwtk/jjwt · error · java.lang.IllegalArgumentException
Negative skip length
Error message
Negative skip length: ${n} What it means
Argument-validation guard in BaseNCodecInputStream.skip: thrown immediately when the requested skip count n is negative. It is a programming-error signal from the caller (e.g. a miscomputed remaining count or an inverted subtraction), not a decoding failure.
Solutions
- Clamp or validate the skip amount at the call site (e.g. Math.max(0, n)) before invoking skip
- Fix the arithmetic that produced the negative value (often an underflow in a remaining-bytes computation)
- If a negative value can legitimately occur from external input, guard it and skip nothing instead of calling skip
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at impl/src/main/java/io/jsonwebtoken/impl/io/BaseNCodecInputStream.java:218 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/7355d86d989059b2.
Report an issue: GitHub.
Appendix: source
Thrown at impl/src/main/java/io/jsonwebtoken/impl/io/BaseNCodecInputStream.java:218
*
* @throws IOException if this method is invoked
* @since 1.7
*/
@Override
public synchronized void reset() throws IOException {
throw new IOException("mark/reset not supported");
}
/**
* {@inheritDoc}
*
* @throws IllegalArgumentException if the provided skip length is negative
* @since 1.7
*/
@Override
public long skip(final long n) throws IOException {
if (n < 0) {
throw new IllegalArgumentException("Negative skip length: " + n);
}
// skip in chunks of 512 bytes
final byte[] b = new byte[512];
long todo = n;
while (todo > 0) {
int len = (int) Math.min(b.length, todo);
len = this.read(b, 0, len);
if (len == BaseNCodec.EOF) {
break;
}
todo -= len;
}
return n - todo;
}
}View on GitHub (pinned to fb71496164)