apache/hadoop · error · UnsupportedOperationException

Not a ByteBufferPositionedReadable: ${in}

Error message

Not a ByteBufferPositionedReadable: ${in}

What it means

WrappedIO.byteBufferPositionedReadable_readFully(InputStream, long, ByteBuffer) delegates positional byte-buffer (vectored) reads to ByteBufferPositionedReadable.readFully. It performs a strict `in instanceof ByteBufferPositionedReadable` check and throws UnsupportedOperationException when the stream passed in does not directly implement that interface. Note that unlike the companion probe byteBufferPositionedReadable_readFullyAvailable (WrappedIO.java:233), this method does NOT unwrap FSDataInputStream, so passing an FSDataInputStream itself always fails because that wrapper class does not implement the interface.

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/wrappedio/WrappedIO.java:218

   * @throws IOException early checks like failure to resolve path cause IO failures
   */
  public static Path fileSystem_getEnclosingRoot(FileSystem fs, Path path) throws IOException {
    return fs.getEnclosingRoot(path);
  }

  /**
   * Delegate to {@link ByteBufferPositionedReadable#read(long, ByteBuffer)}.
   * @param in input stream
   * @param position position within file
   * @param buf the ByteBuffer to receive the results of the read operation.
   * Note: that is the default behaviour of {@link FSDataInputStream#readFully(long, ByteBuffer)}.
   */
  public static void byteBufferPositionedReadable_readFully(
      InputStream in,
      long position,
      ByteBuffer buf) {
    if (!(in instanceof ByteBufferPositionedReadable)) {
      throw new UnsupportedOperationException("Not a ByteBufferPositionedReadable: " + in);
    }
    uncheckIOExceptions(() -> {
      ((ByteBufferPositionedReadable) in).readFully(position, buf);
      return null;
    });
  }

  /**
   * Probe to see if the input stream is an instance of ByteBufferPositionedReadable.
   * If the stream is an FSDataInputStream, the wrapped stream is checked.
   * @param in input stream
   * @return true if the stream implements the interface (including a wrapped stream)
   * and that it declares the stream capability.
   */
  public static boolean byteBufferPositionedReadable_readFullyAvailable(
      InputStream in) {
    if (!(in instanceof ByteBufferPositionedReadable)) {
      return false;

View on GitHub (pinned to 2add963021)

Solutions

  1. Probe first: if (WrappedIO.byteBufferPositionedReadable_readFullyAvailable(in)) — it unwraps FSDataInputStream and verifies the in:preadbytebuffer stream capability before you call the read.
  2. If the probe returns true for an FSDataInputStream, pass ((FSDataInputStream) in).getWrappedStream() to byteBufferPositionedReadable_readFully.
  3. If the filesystem lacks the capability, fall back to byte-array positioned reads: FSDataInputStream.readFully(position, buf.array(), buf.arrayOffset() + buf.position(), remaining).
  4. Upgrade the filesystem connector (hadoop-hdfs-client, S3A, ABFS) to a version whose input streams implement ByteBufferPositionedReadable.

Example fix

// before
try (FSDataInputStream in = fs.open(path)) {
  WrappedIO.byteBufferPositionedReadable_readFully(in, pos, buf); // throws: FSDataInputStream is not a ByteBufferPositionedReadable
}

// after
try (FSDataInputStream in = fs.open(path)) {
  if (WrappedIO.byteBufferPositionedReadable_readFullyAvailable(in)) {
    WrappedIO.byteBufferPositionedReadable_readFully(
        in.getWrappedStream(), pos, buf);
  } else {
    in.readFully(pos, buf.array(), buf.arrayOffset() + buf.position(), buf.remaining());
    buf.position(buf.position() + buf.remaining());
  }
}
Defensive patterns

Strategy: type-guard

Validate before calling

import org.apache.hadoop.io.wrappedio.WrappedIO;
import org.apache.hadoop.fs.FSDataInputStream;

boolean canVectoredPread(InputStream in) {
  return WrappedIO.byteBufferPositionedReadable_readFullyAvailable(in); // unwraps FSDataInputStream + checks in:preadbytebuffer
}

Type guard

static boolean isByteBufferPositionedReadable(InputStream in) {
  if (in instanceof FSDataInputStream) {
    in = ((FSDataInputStream) in).getWrappedStream();
  }
  return in instanceof org.apache.hadoop.fs.ByteBufferPositionedReadable;
}

Try / catch

try {
  WrappedIO.byteBufferPositionedReadable_readFully(rawStream, pos, buf);
} catch (UnsupportedOperationException e) {
  // stream lacks vectored pread; fall back to byte-array positioned read
  fdis.readFully(pos, buf.array(), buf.arrayOffset() + buf.position(), buf.remaining());
}

Prevention

When it happens

Trigger: Calling WrappedIO.byteBufferPositionedReadable_readFully with: (a) an FSDataInputStream instead of its underlying getWrappedStream(); (b) a plain java.io stream such as FileInputStream, ByteArrayInputStream, or an HTTP stream; (c) a filesystem-specific stream that lacks the StreamCapabilities.PREADBYTEBUFFER capability (local raw files, older object-store connectors).

Common situations: Columnar readers (Parquet/ORC) routed through WrappedIO reading from filesystems without vectored-IO support; mixing Hadoop artifact versions where the connector predates ByteBufferPositionedReadable; passing fs.open(path) directly instead of fs.open(path).getWrappedStream().

Related errors


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