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
- Skip the alternate-replica fallback for encrypted reads and reopen the stream instead
- Catch UnsupportedOperationException and re-open the file rather than switching source
- 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
- Treat seekToNewSource as optional failover, not a required step in read retry logic
- Validate targetPos >= 0 before calling (Preconditions also rejects negatives)
- Design recovery paths around reopen rather than replica switching for encrypted files
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
- ${className} does not support seek.
- ${className} does not support positioned read.
- ${className} does not support positioned reads with byte buf
- ${className} does not support positioned readFully.
- Cannot seek to a negative offset
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/70f5ffafd21291a4.
Report an issue: GitHub.