{"record":{"id":"1ab0fb4cfe7b4fbf","repo":"apache/hadoop","slug":"mark-reset-not-supported-on-this-stream","errorCode":null,"errorMessage":"mark()/reset() not supported on this stream","messagePattern":"mark\\(\\)/reset\\(\\) not supported on this stream","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsInputStream.java","lineNumber":902,"sourceCode":"  public synchronized void close() throws IOException {\n    LOG.debug(\"Closing {}\", this);\n    closed = true;\n    if (getReadBufferManager() != null) {\n      getReadBufferManager().purgeBuffersForStream(this);\n    }\n    buffer = null; // de-reference the buffer so it can be GC'ed sooner\n    if (contextEncryptionAdapter != null) {\n      contextEncryptionAdapter.destroy();\n    }\n  }\n\n  /**\n   * Not supported by this stream. Throws {@link UnsupportedOperationException}\n   * @param readlimit ignored\n   */\n  @Override\n  public synchronized void mark(int readlimit) {\n    throw new UnsupportedOperationException(\"mark()/reset() not supported on this stream\");\n  }\n\n  /**\n   * Not supported by this stream. Throws {@link UnsupportedOperationException}\n   */\n  @Override\n  public synchronized void reset() throws IOException {\n    throw new UnsupportedOperationException(\"mark()/reset() not supported on this stream\");\n  }\n\n  /**\n   * gets whether mark and reset are supported by {@code ADLFileInputStream}. Always returns false.\n   *\n   * @return always {@code false}\n   */\n  @Override\n  public boolean markSupported() {\n    return false;","sourceCodeStart":884,"sourceCodeEnd":920,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsInputStream.java#L884-L920","documentation":"AbfsInputStream.mark(int readlimit) always throws UnsupportedOperationException(\"mark()/reset() not supported on this stream\"). ABFS streams are seekable over HTTP range reads and keep no mark buffer; markSupported() always returns false so callers can probe the capability. FSDataInputStream does not add mark support — it delegates to the wrapped stream — so the exception surfaces even through the Hadoop wrapper.","triggerScenarios":"Calling in.mark(readLimit) directly on an FSDataInputStream backed by abfs://; third-party libraries (format sniffers, compression codecs, magic-byte detectors) that call mark() without first checking markSupported(); code ported from BufferedInputStream/FileInputStream idioms.","commonSituations":"Using a file-format detection utility that assumes mark/reset; readers that emulate rewind via mark/reset instead of seek; wrapping in FSDataInputStream and assuming Hadoop 'fixes' mark support.","solutions":["Check in.markSupported() before calling mark() and fall back to getPos()/seek()","Use getPos() + seek(pos) for rewind — cheap on ABFS since reads are positional range requests","Wrap the stream in java.io.BufferedInputStream when you only need a small lookahead window (its own mark/reset work on the buffer)"],"exampleFix":"// before\nin.mark(64);          // UnsupportedOperationException\nin.read(header);\nin.reset();\n\n// after (seekable stream)\nlong pos = in.getPos();\nin.read(header);\nin.seek(pos);          // rewind via seek\n\n// after (small lookahead, generic InputStream)\nif (in.markSupported()) {\n  in.mark(64); in.read(header); in.reset();\n} else {\n  long p = in.getPos(); in.read(header); in.seek(p);\n}","handlingStrategy":"validation","validationCode":"// Capability check before marking\nif (in.markSupported()) {\n  in.mark(readLimit);\n} else {\n  long pos = in.getPos();   // seekable fallback\n  ... read lookahead ...\n  in.seek(pos);\n}","typeGuard":"// Java capability guard for mark/reset on Hadoop streams\nstatic boolean supportsMark(java.io.InputStream in) {\n  return in != null && in.markSupported();\n}\n\n// usage\nif (supportsMark(in)) { in.mark(64); ... } else { /* seek-based lookahead */ }","tryCatchPattern":"try {\n  in.mark(64);\n} catch (UnsupportedOperationException e) {\n  // ABFS streams never support mark; switch to seek/getPos strategy\n  long p = in.getPos(); ... in.seek(p);\n}","preventionTips":["Always gate mark() behind markSupported() — it is false for abfs:// streams","Prefer getPos()/seek() for rewind on seekable FileSystem streams","Wrap in BufferedInputStream when handing the stream to mark-dependent libraries"],"tags":["azure-blob","abfs","unsupported-operation","mark-reset","hadoop"],"backgroundTag":"mark-reset-unsupported","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}