{"record":{"id":"c0bba5a9685b143d","repo":"apache/hadoop","slug":"seek-operations-are-unsupported-by-the-internal-st","errorCode":null,"errorMessage":"seek operations are unsupported by the internal stream","messagePattern":"seek operations are unsupported by the internal stream","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hadoop-tools/hadoop-distcp/src/main/java/org/apache/hadoop/tools/util/ThrottledInputStream.java","lineNumber":151,"sourceCode":"   */\n  public long getTotalSleepTime() {\n    return totalSleepTime;\n  }\n\n  /** {@inheritDoc} */\n  @Override\n  public String toString() {\n    return \"ThrottledInputStream{\" +\n        \"bytesRead=\" + bytesRead +\n        \", maxBytesPerSec=\" + maxBytesPerSec +\n        \", bytesPerSec=\" + getBytesPerSec() +\n        \", totalSleepTime=\" + totalSleepTime +\n        '}';\n  }\n\n  private void checkSeekable() throws IOException {\n    if (!(rawStream instanceof Seekable)) {\n      throw new UnsupportedOperationException(\n          \"seek operations are unsupported by the internal stream\");\n    }\n  }\n\n  @Override\n  public void seek(long pos) throws IOException {\n    checkSeekable();\n    ((Seekable) rawStream).seek(pos);\n  }\n\n  @Override\n  public long getPos() throws IOException {\n    checkSeekable();\n    return ((Seekable) rawStream).getPos();\n  }\n\n  @Override\n  public boolean seekToNewSource(long targetPos) throws IOException {","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-tools/hadoop-distcp/src/main/java/org/apache/hadoop/tools/util/ThrottledInputStream.java#L133-L169","documentation":"ThrottledInputStream delegates seek()/getPos() to the wrapped raw stream only after checkSeekable() confirms it implements org.apache.hadoop.fs.Seekable. If the underlying stream is not Seekable (e.g. a plain HTTP/object-store input stream), calling seek or any position-dependent path raises this UnsupportedOperationException before any delegation occurs.","triggerScenarios":"Wrapping a non-seekable raw stream in ThrottledInputStream and then calling seek() or getPos()-dependent flows; position-based reads (such as RetriableFileCopyCommand's offset copies) running against connectors whose streams only support sequential reads.","commonSituations":"Library code assuming FileSystem.open() always yields a seekable stream; S3A/HTTP-backed input streams; custom tools reusing distcp's ThrottledInputStream with arbitrary streams.","solutions":["Test the raw stream with 'instanceof Seekable' before wrapping or calling seek","Open files through a filesystem returning seekable streams (HDFS), or buffer the data locally when random access is needed","Restructure to sequential reads: close and re-open the stream at the required offset instead of seeking","Pass a Seekable-capable stream into ThrottledInputStream whenever positioning is required"],"exampleFix":"// before\nInputStream raw = fs.open(path);          // connector stream, not Seekable\nThrottledInputStream in = new ThrottledInputStream(raw, 10 * 1024 * 1024);\nin.seek(4096);                            // UnsupportedOperationException\n\n// after\nInputStream raw = fs.open(path);\nThrottledInputStream in = new ThrottledInputStream(raw, 10 * 1024 * 1024);\nif (raw instanceof Seekable) {\n  in.seek(4096);\n} else {\n  in.close();\n  try (InputStream at = openAtOffset(path, 4096)) {  // re-open positioned\n    /* sequential read */\n  }\n}","handlingStrategy":"type-guard","validationCode":"// guard before any positioning call\nif (!(rawStream instanceof Seekable)) {\n  throw new UnsupportedOperationException(\n      \"positioning needs a seekable stream, got: \" + rawStream.getClass());\n}","typeGuard":"static boolean isSeekable(InputStream in) {\n  return in instanceof Seekable;\n}","tryCatchPattern":null,"preventionTips":["Check 'instanceof Seekable' on raw streams before wrapping them in ThrottledInputStream","Buffer non-seekable streams locally when random access is required","Prefer re-opening a stream at an offset over seeking non-positioned streams"],"tags":["distcp","hadoop","stream","seek","unsupported-operation"],"backgroundTag":"unsupported-stream-operation","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}