apache/hadoop · error · UnsupportedOperationException

mark()/reset() not supported on this stream

Error message

mark()/reset() not supported on this stream

What it means

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.

Source

Thrown at hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsInputStream.java:902

  public synchronized void close() throws IOException {
    LOG.debug("Closing {}", this);
    closed = true;
    if (getReadBufferManager() != null) {
      getReadBufferManager().purgeBuffersForStream(this);
    }
    buffer = null; // de-reference the buffer so it can be GC'ed sooner
    if (contextEncryptionAdapter != null) {
      contextEncryptionAdapter.destroy();
    }
  }

  /**
   * Not supported by this stream. Throws {@link UnsupportedOperationException}
   * @param readlimit ignored
   */
  @Override
  public synchronized void mark(int readlimit) {
    throw new UnsupportedOperationException("mark()/reset() not supported on this stream");
  }

  /**
   * Not supported by this stream. Throws {@link UnsupportedOperationException}
   */
  @Override
  public synchronized void reset() throws IOException {
    throw new UnsupportedOperationException("mark()/reset() not supported on this stream");
  }

  /**
   * gets whether mark and reset are supported by {@code ADLFileInputStream}. Always returns false.
   *
   * @return always {@code false}
   */
  @Override
  public boolean markSupported() {
    return false;

View on GitHub (pinned to 2add963021)

Solutions

  1. Check in.markSupported() before calling mark() and fall back to getPos()/seek()
  2. Use getPos() + seek(pos) for rewind — cheap on ABFS since reads are positional range requests
  3. Wrap the stream in java.io.BufferedInputStream when you only need a small lookahead window (its own mark/reset work on the buffer)

Example fix

// before
in.mark(64);          // UnsupportedOperationException
in.read(header);
in.reset();

// after (seekable stream)
long pos = in.getPos();
in.read(header);
in.seek(pos);          // rewind via seek

// after (small lookahead, generic InputStream)
if (in.markSupported()) {
  in.mark(64); in.read(header); in.reset();
} else {
  long p = in.getPos(); in.read(header); in.seek(p);
}
Defensive patterns

Strategy: validation

Validate before calling

// Capability check before marking
if (in.markSupported()) {
  in.mark(readLimit);
} else {
  long pos = in.getPos();   // seekable fallback
  ... read lookahead ...
  in.seek(pos);
}

Type guard

// Java capability guard for mark/reset on Hadoop streams
static boolean supportsMark(java.io.InputStream in) {
  return in != null && in.markSupported();
}

// usage
if (supportsMark(in)) { in.mark(64); ... } else { /* seek-based lookahead */ }

Try / catch

try {
  in.mark(64);
} catch (UnsupportedOperationException e) {
  // ABFS streams never support mark; switch to seek/getPos strategy
  long p = in.getPos(); ... in.seek(p);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/1ab0fb4cfe7b4fbf. Report an issue: GitHub.