apache/hadoop · error · UnsupportedOperationException

${className} does not support seekToNewSource.

Error message

${className} does not support seekToNewSource.

What it means

seekToNewSource(long) is the read-replica-failure fallback API. CryptoInputStream first rejects negative targetPos via Preconditions, then requires `in instanceof Seekable` and throws UnsupportedOperationException naming the wrapped class otherwise. So on encrypted streams this failover path exists only when the inner stream is Seekable.

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CryptoInputStream.java:699

    return false;
  }
  
  @Override
  public void mark(int readLimit) {
  }
  
  @Override
  public void reset() throws IOException {
    throw new IOException("Mark/reset not supported");
  }

  @Override
  public boolean seekToNewSource(long targetPos) throws IOException {
    Preconditions.checkArgument(targetPos >= 0, 
        "Cannot seek to negative offset.");
    checkStream();
    if (!(in instanceof Seekable)) {
      throw new UnsupportedOperationException(in.getClass().getCanonicalName()
          + " does not support seekToNewSource.");
    }
    boolean result = ((Seekable) in).seekToNewSource(targetPos);
    resetStreamOffset(targetPos);
    return result;
  }

  @Override
  public ByteBuffer read(ByteBufferPool bufferPool, int maxLength,
      EnumSet<ReadOption> opts) throws IOException,
      UnsupportedOperationException {
    checkStream();
    if (outBuffer.remaining() > 0) {
      if (!(in instanceof Seekable)) {
        throw new UnsupportedOperationException(in.getClass().getCanonicalName()
            + " does not support seek.");
      }
      // Have some decrypted data unread, need to reset.

View on GitHub (pinned to 2add963021)

Solutions

  1. Skip the alternate-replica fallback for encrypted reads and reopen the stream instead
  2. Catch UnsupportedOperationException and re-open the file rather than switching source
  3. Ensure the wrapped stream implements Seekable if you control the stream implementation

Example fix

// before
boolean moved = fsIn.seekToNewSource(pos); // UOE when inner stream not Seekable

// after
try {
  boolean moved = fsIn.seekToNewSource(pos);
} catch (UnsupportedOperationException e) {
  fsIn = fs.open(path); // reopen as the recovery path
  fsIn.seek(pos);
}
Defensive patterns

Strategy: try-catch

Try / catch

try {
  moved = fsIn.seekToNewSource(pos);
} catch (UnsupportedOperationException e) {
  fsIn = fs.open(path); // reopen as the failover path
  fsIn.seek(pos);
}

Prevention

When it happens

Trigger: Calling seekToNewSource() on encrypted files when the underlying stream is not Seekable; client retry logic attempting to switch replicas after a checksum/read error.

Common situations: Custom retry layers in InputFormats implementing replica failover; unit tests with mock inner streams that only implement InputStream.

Related errors


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