{"record":{"id":"7448d2c9e814b2df","repo":"jwtk/jjwt","slug":"number-of-characters-to-skip-is-less-than-zero","errorCode":null,"errorMessage":"Number of characters to skip is less than zero: ${n}","messagePattern":"Number of characters to skip 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":266,"sourceCode":"    /**\n     * Reset the reader to the last marked position (or the beginning if\n     * mark has not been called).\n     */\n    @Override\n    public void reset() {\n        idx = mark;\n    }\n\n    /**\n     * Skip the specified number of characters.\n     *\n     * @param n The number of characters to skip\n     * @return The actual number of characters skipped\n     */\n    @Override\n    public long skip(final long n) {\n        if (n < 0) {\n            throw new IllegalArgumentException(\"Number of characters to skip is less than zero: \" + n);\n        }\n        if (idx >= end()) {\n            return 0;\n        }\n        final int dest = (int) Math.min(end(), idx + n);\n        final int count = dest - idx;\n        idx = dest;\n        return count;\n    }\n\n    /**\n     * Returns the index in the character sequence to start reading from, taking into account its length.\n     *\n     * @return The start index in the character sequence (inclusive).\n     */\n    private int start() {\n        return Math.min(charSequence.length(), start);\n    }","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/jwtk/jjwt/blob/fb71496164c71442d08adec4571d9616ed5e1b8d/impl/src/main/java/io/jsonwebtoken/impl/io/CharSequenceReader.java#L248-L284","documentation":"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.","triggerScenarios":"Thrown at impl/src/main/java/io/jsonwebtoken/impl/io/CharSequenceReader.java:266 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Validate the skip amount before calling (skip only when n > 0, or clamp with Math.max(0, n))","Fix the computation that produced the negative count (frequently 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"}