{"record":{"id":"7355d86d989059b2","repo":"jwtk/jjwt","slug":"negative-skip-length-n","errorCode":null,"errorMessage":"Negative skip length: ${n}","messagePattern":"Negative skip length: (.+?)","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"impl/src/main/java/io/jsonwebtoken/impl/io/BaseNCodecInputStream.java","lineNumber":218,"sourceCode":"     *\n     * @throws IOException if this method is invoked\n     * @since 1.7\n     */\n    @Override\n    public synchronized void reset() throws IOException {\n        throw new IOException(\"mark/reset not supported\");\n    }\n\n    /**\n     * {@inheritDoc}\n     *\n     * @throws IllegalArgumentException if the provided skip length is negative\n     * @since 1.7\n     */\n    @Override\n    public long skip(final long n) throws IOException {\n        if (n < 0) {\n            throw new IllegalArgumentException(\"Negative skip length: \" + n);\n        }\n\n        // skip in chunks of 512 bytes\n        final byte[] b = new byte[512];\n        long todo = n;\n\n        while (todo > 0) {\n            int len = (int) Math.min(b.length, todo);\n            len = this.read(b, 0, len);\n            if (len == BaseNCodec.EOF) {\n                break;\n            }\n            todo -= len;\n        }\n\n        return n - todo;\n    }\n}","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/jwtk/jjwt/blob/fb71496164c71442d08adec4571d9616ed5e1b8d/impl/src/main/java/io/jsonwebtoken/impl/io/BaseNCodecInputStream.java#L200-L236","documentation":"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.","triggerScenarios":"Thrown at impl/src/main/java/io/jsonwebtoken/impl/io/BaseNCodecInputStream.java:218 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"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"}