{"record":{"id":"d8cf76b0f8a89510","repo":"seaweedfs/seaweedfs","slug":"in-is-not-an-instance-of-seekable-or-positionedrea","errorCode":null,"errorMessage":"In is not an instance of Seekable or PositionedReadable","messagePattern":"In is not an instance of Seekable or PositionedReadable","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"other/java/hdfs3/src/main/java/seaweed/hdfs/BufferedByteBufferReadableInputStream.java","lineNumber":13,"sourceCode":"package seaweed.hdfs;\n\nimport org.apache.hadoop.fs.*;\n\nimport java.io.IOException;\nimport java.nio.ByteBuffer;\n\npublic class BufferedByteBufferReadableInputStream extends BufferedFSInputStream implements ByteBufferReadable {\n\n    public BufferedByteBufferReadableInputStream(FSInputStream in, int size) {\n        super(in, size);\n        if (!(in instanceof Seekable) || !(in instanceof PositionedReadable)) {\n            throw new IllegalArgumentException(\"In is not an instance of Seekable or PositionedReadable\");\n        }\n    }\n\n    @Override\n    public int read(ByteBuffer buf) throws IOException {\n        if (this.in instanceof ByteBufferReadable) {\n            return ((ByteBufferReadable)this.in).read(buf);\n        } else {\n            throw new UnsupportedOperationException(\"Byte-buffer read unsupported by input stream\");\n        }\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":26,"githubUrl":"https://github.com/seaweedfs/seaweedfs/blob/1c926e8fac8e8001ce25efa1027c90b02b4a1804/other/java/hdfs3/src/main/java/seaweed/hdfs/BufferedByteBufferReadableInputStream.java#L1-L26","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Wrap the real SeaweedInputStream (it implements both interfaces) instead of an intermediate custom stream","For mocks, make them implement Seekable and PositionedReadable or use FSDataInputStream in tests","Align Hadoop versions across the classpath so instanceof checks see the same interface types"],"exampleFix":"// before\nnew BufferedByteBufferReadableInputStream(customSockStream, size); // customSockStream lacks interfaces\n\n// after\nFSInputStream in = (customSockStream instanceof Seekable && customSockStream instanceof PositionedReadable)\n  ? customSockStream\n  : new seaweedFileSystemStore.openFileForRead(path, stats);\nnew BufferedByteBufferReadableInputStream(in, size);","handlingStrategy":"type-guard","validationCode":"if (!(in instanceof Seekable) || !(in instanceof PositionedReadable)) {\n  throw new IllegalArgumentException(\"inner stream must be Seekable + PositionedReadable: \" + in.getClass());\n}","typeGuard":"static boolean wrappable(FSInputStream in) {\n  return in instanceof Seekable && in instanceof PositionedReadable;\n}","tryCatchPattern":null,"preventionTips":["Wrap the real SeaweedInputStream; do not interpose custom stream shims","Make test mocks implement Seekable and PositionedReadable","Keep one Hadoop version on the classpath so interface identity is stable"],"tags":["java","hadoop3","filesystem","type-guard","constructor"],"backgroundTag":null,"analyzedSha":"1c926e8fac8e8001ce25efa1027c90b02b4a1804","analyzedAt":"2026-08-15T15:37:02.018Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}