{"record":{"id":"0903227d11c74987","repo":"jhy/jsoup","slug":"mark-invalid","errorCode":null,"errorMessage":"Mark invalid","messagePattern":"Mark invalid","errorType":"exception","errorClass":"UncheckedIOException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/jsoup/parser/CharacterReader.java","lineNumber":139,"sourceCode":"        scanBufferForNewlines(); // if enabled, we index newline positions for line number tracking\n    }\n\n    void mark() {\n        // make sure there is enough look ahead capacity\n        if (bufLength - bufPos < RewindLimit)\n            fillPoint = 0;\n\n        bufferUp();\n        bufMark = bufPos;\n    }\n\n    void unmark() {\n        bufMark = -1;\n    }\n\n    void rewindToMark() {\n        if (bufMark == -1)\n            throw new UncheckedIOException(new IOException(\"Mark invalid\"));\n\n        bufPos = bufMark;\n        unmark();\n    }\n\n    /**\n     * Gets the position currently read to in the content. Starts at 0.\n     * @return current position\n     */\n    public int pos() {\n        // consuming EOF advances to a virtual position so it can be unconsumed; don't expose that beyond the input\n        return consumed + Math.min(bufPos, bufLength);\n    }\n\n    /**\n     Enables or disables line number tracking. By default, will be <b>off</b>.Tracking line numbers improves the\n     legibility of parser error messages, for example. Tracking should be enabled before any content is read to be of\n     use.","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/jhy/jsoup/blob/9851ac5d9c576c6888910b5a51a2362bbc978959/src/main/java/org/jsoup/parser/CharacterReader.java#L121-L157","documentation":"Internal state error in CharacterReader.rewindToMark: it fires when bufMark is still the sentinel -1, i.e. mark() was never called (or unmark()/rewindToMark already consumed the mark) before a rewind was attempted. It is a marker of a reader-protocol violation by calling code that rewinds without an outstanding mark.","triggerScenarios":"Thrown at src/main/java/org/jsoup/parser/CharacterReader.java:139 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Call mark() before rewinding; every rewindToMark() must be paired with a preceding mark().","Do not rewind twice on the same mark — rewindToMark() clears the mark via unmark(); re-mark if you need to rewind again.","If wrapping CharacterReader, preserve the mark protocol: mark before any speculative consume-then-rewind sequence, since bufferUp() may invalidate assumptions."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"9851ac5d9c576c6888910b5a51a2362bbc978959","analyzedAt":"2026-09-08T15:22:04.931Z","contentChangedAt":"2026-09-08T15:22:04.931Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}