{"record":{"id":"aca6a8791de43cea","repo":"apache/hadoop","slug":"mark-not-set","errorCode":null,"errorMessage":"Mark not set","messagePattern":"Mark not set","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/LimitInputStream.java","lineNumber":95,"sourceCode":"    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":77,"sourceCodeEnd":110,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/LimitInputStream.java#L77-L110","documentation":"The companion guard in LimitInputStream.reset(): even on mark-capable streams it throws IOException(\"Mark not set\") when mark(readLimit) was never called on this wrapper (the internal mark field is still -1). Marking is per-instance state, so re-wrapping the stream between mark and reset also loses the mark.","triggerScenarios":"Calling reset() before any mark(); constructing a new LimitInputStream over the same source between the mark() and reset() calls; parser state machines where mark is conditional but reset is unconditional.","commonSituations":"Lookahead code refactored so the mark call moved into a branch; per-record utility methods that assume an outer layer already marked; resetting after the read budget (left) was exhausted by design.","solutions":["Call mark(readLimit) with a limit at least as large as the region you may re-read, immediately before reading it","Pair mark/reset inside one method so they cannot be separated by a refactor","Track a marked flag (or check the wrapper's state) before reset()"],"exampleFix":"// before\nparser.maybeMark();\nparser.consume();\nlimitIn.reset(); // throws if maybeMark skipped the mark\n\n// after\nlimitIn.mark(MAX_LOOKAHEAD);\ntry {\n  parser.consume();\n} finally {\n  limitIn.reset();\n}","handlingStrategy":"validation","validationCode":"boolean marked = false;\nif (in.markSupported()) { in.mark(MAX_LOOKAHEAD); marked = true; }\n... // read\nif (marked) { in.reset(); }","typeGuard":null,"tryCatchPattern":"try { in.reset(); } catch (IOException e) { if (\"Mark not set\".equals(e.getMessage())) { /* mark was never made: re-read from a saved offset instead */ } else throw e; }","preventionTips":["Keep mark() and reset() in the same method so refactors cannot separate them","Track a marked flag alongside the stream","Choose a readLimit larger than the maximum lookahead region"],"tags":["hadoop","java","io","mark-reset","stream-wrapper"],"backgroundTag":"stream-mark-not-set","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}