{"record":{"id":"0fd0a8f45b6b5604","repo":"apache/hadoop","slug":"mark-reset-not-supported-0fd0a8","errorCode":null,"errorMessage":"Mark/reset not supported","messagePattern":"Mark/reset not supported","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java","lineNumber":1756,"sourceCode":"    }\n\n    final long remaining = getFileLength() - pos;\n    return remaining <= Integer.MAX_VALUE? (int)remaining: Integer.MAX_VALUE;\n  }\n\n  /**\n   * We definitely don't support marks\n   */\n  @Override\n  public boolean markSupported() {\n    return false;\n  }\n  @Override\n  public void mark(int readLimit) {\n  }\n  @Override\n  public void reset() throws IOException {\n    throw new IOException(\"Mark/reset not supported\");\n  }\n\n  @Override\n  public int read(long position, final ByteBuffer buf) throws IOException {\n    if (!buf.hasRemaining()) {\n      return 0;\n    }\n    return pread(position, buf);\n  }\n\n  @Override\n  public void readFully(long position, final ByteBuffer buf)\n      throws IOException {\n    int nread = 0;\n    while (buf.hasRemaining()) {\n      int nbytes = read(position + nread, buf);\n      if (nbytes < 0) {\n        throw new EOFException(FSExceptionMessages.EOF_IN_READ_FULLY);","sourceCodeStart":1738,"sourceCodeEnd":1774,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java#L1738-L1774","documentation":"DFSInputStream.markSupported() returns false, mark() is a no-op, and reset() unconditionally throws IOException('Mark/reset not supported'). HDFS input streams do no front buffering (data streams straight from a Datanode), so the mark/reset contract cannot be honored. Any library that formats-sniffs by calling mark()/reset() will blow up on a raw FSDataInputStream.","triggerScenarios":"Passing a raw HDFS FSDataInputStream to code that calls reset(): content-type detection (Apache Tika, mime4j), ImageIO.read, audio/video probe libraries, XML BOM sniffing. Sequence: library calls in.mark(readLimit), reads magic bytes, calls in.reset() -> IOException.","commonSituations":"Running Tika/document parsers directly over fs.open(path) output; ingest pipelines probing file type before dispatch; porting code that worked on FileInputStream/BufferedInputStream to HDFS paths.","solutions":["Wrap the HDFS stream in a BufferedInputStream large enough for the detector's readLimit: new BufferedInputStream(fsin, 64*1024) - mark/reset then works.","For small files, read fully into memory and hand the library a ByteArrayInputStream (mark/reset supported, no wrapping complexity).","Use library helpers that buffer for you, e.g. TikaInputStream.get(stream, metadata) instead of the raw stream.","If it is your own code, replace mark/reset bookkeeping with explicit getPos()/seek(), which HDFS supports natively."],"exampleFix":"// before\nFSDataInputStream in = fs.open(path);\nString type = detector.detect(in, metadata); // calls mark()/reset() -> throws\n\n// after\nFSDataInputStream in = fs.open(path);\nBufferedInputStream buffered = new BufferedInputStream(in, 64 * 1024);\nString type = detector.detect(buffered, metadata); // mark/reset on the buffer\nin.seek(0); // when the raw stream must be re-read afterwards","handlingStrategy":"type-guard","validationCode":"InputStream probe = fs.open(path);\nif (!probe.markSupported()) {\n  probe = new BufferedInputStream(probe, 64 * 1024); // now mark/reset works\n}","typeGuard":"boolean supportsMarkReset(InputStream in) {\n  return in != null && in.markSupported();\n}\n\n// usage\nif (supportsMarkReset(in)) {\n  in.mark(readLimit);\n  sniff(in);\n  in.reset();\n} else {\n  in = new BufferedInputStream(in, readLimit); // then mark/reset safely\n}","tryCatchPattern":null,"preventionTips":["Check markSupported() before any mark/reset dance - it is the documented contract.","Wrap remote streams (HDFS, S3A) in BufferedInputStream before handing them to detectors/parsers.","For small files, hand libraries a ByteArrayInputStream and keep the remote stream seekable for re-reads.","Prefer explicit getPos()/seek() bookkeeping over mark/reset in your own HDFS code."],"tags":["hdfs","hdfs-client","mark-reset","compatibility","io"],"backgroundTag":"mark-reset-not-supported","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}