seaweedfs/seaweedfs · error · IllegalArgumentException

In is not an instance of Seekable or PositionedReadable

Error message

In is not an instance of Seekable or PositionedReadable

What it means

BufferedByteBufferReadableInputStream's constructor asserts that the wrapped FSInputStream implements both Seekable and PositionedReadable — the minimum Hadoop requires of a seekable buffered stream. Passing anything else (a stream type that only superficially extends FSInputStream, a dynamic proxy, or a mock) fails fast with IllegalArgumentException before the first read.

Source

Thrown at other/java/hdfs3/src/main/java/seaweed/hdfs/BufferedByteBufferReadableInputStream.java:13

package seaweed.hdfs;

import org.apache.hadoop.fs.*;

import java.io.IOException;
import java.nio.ByteBuffer;

public class BufferedByteBufferReadableInputStream extends BufferedFSInputStream implements ByteBufferReadable {

    public BufferedByteBufferReadableInputStream(FSInputStream in, int size) {
        super(in, size);
        if (!(in instanceof Seekable) || !(in instanceof PositionedReadable)) {
            throw new IllegalArgumentException("In is not an instance of Seekable or PositionedReadable");
        }
    }

    @Override
    public int read(ByteBuffer buf) throws IOException {
        if (this.in instanceof ByteBufferReadable) {
            return ((ByteBufferReadable)this.in).read(buf);
        } else {
            throw new UnsupportedOperationException("Byte-buffer read unsupported by input stream");
        }
    }
}

View on GitHub (pinned to 1c926e8fac)

Solutions

  1. Wrap the real SeaweedInputStream (it implements both interfaces) instead of an intermediate custom stream
  2. For mocks, make them implement Seekable and PositionedReadable or use FSDataInputStream in tests
  3. Align Hadoop versions across the classpath so instanceof checks see the same interface types

Example fix

// before
new BufferedByteBufferReadableInputStream(customSockStream, size); // customSockStream lacks interfaces

// after
FSInputStream in = (customSockStream instanceof Seekable && customSockStream instanceof PositionedReadable)
  ? customSockStream
  : new seaweedFileSystemStore.openFileForRead(path, stats);
new BufferedByteBufferReadableInputStream(in, size);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(in instanceof Seekable) || !(in instanceof PositionedReadable)) {
  throw new IllegalArgumentException("inner stream must be Seekable + PositionedReadable: " + in.getClass());
}

Type guard

static boolean wrappable(FSInputStream in) {
  return in instanceof Seekable && in instanceof PositionedReadable;
}

Prevention

When it happens

Trigger: Wrapping a custom or third-party FSInputStream subclass that does not implement these interfaces (possible via proxies or nonstandard filesystems); unit tests passing mocked streams; wiring a raw socket-backed stream into this buffer layer.

Common situations: Test harnesses with Mockito mocks of FSInputStream; custom filesystem shims layered over the seaweed client; dependency conflicts pulling an old Hadoop version where interface hierarchies differ.

Related errors


AI-assisted analysis of seaweedfs/seaweedfs@1c926e8fac (2026-08-15). Data as JSON: /api/errors/d8cf76b0f8a89510. Report an issue: GitHub.