{"record":{"id":"77697cca335d5997","repo":"apache/hadoop","slug":"mark-not-supported-77697c","errorCode":null,"errorMessage":"Mark not supported","messagePattern":"Mark not supported","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/LimitInputStream.java","lineNumber":92,"sourceCode":"    if (len == 0) {\n      return 0;\n    }\n    if (left == 0) {\n      return -1;\n    }\n\n    len = (int) Math.min(len, left);\n    int result = in.read(b, off, len);\n    if (result != -1) {\n      left -= result;\n    }\n    return result;\n  }\n\n  @Override\n  public synchronized void reset() throws IOException {\n    if (!in.markSupported()) {\n      throw new IOException(\"Mark not supported\");\n    }\n    if (mark == -1) {\n      throw new IOException(\"Mark not set\");\n    }\n\n    in.reset();\n    left = mark;\n  }\n\n  @Override\n  public long skip(long n) throws IOException {\n    n = Math.min(n, left);\n    long skipped = in.skip(n);\n    left -= skipped;\n    return skipped;\n  }\n}\n","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/LimitInputStream.java#L74-L110","documentation":"LimitInputStream wraps an InputStream and enforces a remaining-byte budget. Its reset() is only legal when the wrapped stream itself can mark: it delegates the check to in.markSupported() and throws IOException(\"Mark not supported\") when the underlying stream (FileInputStream, a raw socket stream, etc.) cannot mark/reset.","triggerScenarios":"new LimitInputStream(new FileInputStream(file), limit).reset(); wrapping any non-marking stream and calling mark()/reset(); a record parser that uses mark/reset for lookahead pointed at file or network streams.","commonSituations":"Swapping the underlying stream from BufferedInputStream (supports mark) to FileInputStream or a socket stream; code tested against ByteArrayInputStream (marks fine) but run on files; binary parsers relying on bounded lookahead.","solutions":["Wrap the source in a BufferedInputStream before the LimitInputStream so mark/reset is supported","Check markSupported() before calling reset() and take a non-marking fallback path (re-open or skip-forward)","Restructure the parser to count bytes instead of marking, or use PushbackInputStream.unread()"],"exampleFix":"// before\nInputStream in = new LimitInputStream(new FileInputStream(file), 4096);\nin.mark(64); ... in.reset();\n\n// after\nInputStream in = new LimitInputStream(\n    new BufferedInputStream(new FileInputStream(file)), 4096);\nin.mark(64); ... in.reset();","handlingStrategy":"validation","validationCode":"InputStream src = new BufferedInputStream(new FileInputStream(file)); // marks supported\nLimitInputStream in = new LimitInputStream(src, limit);\n...\nif (!in.markSupported()) { /* re-open stream instead of reset */ }","typeGuard":null,"tryCatchPattern":"try { in.reset(); } catch (IOException e) { if (\"Mark not supported\".equals(e.getMessage())) { /* fall back: re-open source and skip consumed bytes */ } else throw e; }","preventionTips":["Always wrap file/socket sources in BufferedInputStream when the parser needs mark/reset","Check markSupported() before relying on reset","Test parsers against the same stream type production uses, not ByteArrayInputStream"],"tags":["hadoop","java","io","mark-reset","stream-wrapper"],"backgroundTag":"mark-reset-unsupported","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}