apache/cassandra · error · IOException

Mark/Reset not supported

Error message

Mark/Reset not supported

What it means

LengthAvailableInputStream is a minimal wrapper that exposes a stream's length but does not support mark/reset. Calling reset() always throws IOException because markSupported() returns false and mark() is a no-op. This is standard java.io InputStream behavior for streams that cannot rewind their underlying source.

Solutions

  1. Check markSupported() before calling mark()/reset() and only use reset() when it returns true
  2. Buffer the bytes you need to re-read yourself (read into a byte[] and wrap in ByteArrayInputStream, or use PushbackInputStream)
  3. Wrap the stream in BufferedInputStream if the reset distance fits its buffer size, giving you mark/reset support
  4. Restructure the code to re-open the underlying file/channel instead of resetting the stream

Example fix

// before
InputStream in = new LengthAvailableInputStream(channel.newReadLength(), length);
in.mark(1024);
readHeader(in);
in.reset(); // throws IOException: Mark/Reset not supported
// after
InputStream in = new LengthAvailableInputStream(channel.newReadLength(), length);
if (in.markSupported()) {
    in.mark(1024);
    readHeader(in);
    in.reset();
} else {
    byte[] header = new byte[1024];
    readFully(in, header);
    InputStream headerStream = new ByteArrayInputStream(header);
}
Defensive patterns

Strategy: validation

Validate before calling

if (in.markSupported()) { in.mark(1024); ... in.reset(); } else { /* buffer manually */ }

Type guard

boolean canReset = in != null && in.markSupported();

Try / catch

try { in.reset(); } catch (IOException e) { /* fall back to re-open or manual buffer */ }

Prevention

When it happens

Trigger: Calling reset() on a LengthAvailableInputStream (optionally after calling mark(int)), e.g. when client code assumes all InputStreams can rewind or wraps the stream in a reader that transparently uses mark/reset such as PushbackInputStream buffering. Marking then resetting without checking markSupported() first.

Common situations: Code paths that re-read a header or replay bytes after discovering a different format; libraries that mark() speculatively; users copying generic InputStream-handling code that worked on ByteArrayInputStream/BufferedInputStream onto this stream.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/259f38502827af6b. Report an issue: GitHub.

Appendix: source

Thrown at src/java/org/apache/cassandra/io/util/LengthAvailableInputStream.java:90

    {
        return (remainingBytes <= 0) ? 0 : ((remainingBytes > Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int)remainingBytes);
    }

    @Override
    public void close() throws IOException
    {
        in.close();
    }

    @Override
    public synchronized void mark(int readlimit)
    {
    }

    @Override
    public synchronized void reset() throws IOException
    {
        throw new IOException("Mark/Reset not supported");
    }

    @Override
    public boolean markSupported()
    {
        return false;
    }
}

View on GitHub (pinned to 88fd0f6a0e)