{"record":{"id":"e4cf24a78c247545","repo":"apache/hadoop","slug":"seek-not-supported","errorCode":null,"errorMessage":"Seek not supported","messagePattern":"Seek not supported","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ftp/FTPInputStream.java","lineNumber":62,"sourceCode":"    if (client == null || !client.isConnected()) {\n      throw new IllegalArgumentException(\"FTP client null or not connected\");\n    }\n    this.wrappedStream = stream;\n    this.client = client;\n    this.stats = stats;\n    this.pos = 0;\n    this.closed = false;\n  }\n\n  @Override\n  public long getPos() throws IOException {\n    return pos;\n  }\n\n  // We don't support seek.\n  @Override\n  public void seek(long pos) throws IOException {\n    throw new IOException(\"Seek not supported\");\n  }\n\n  @Override\n  public boolean seekToNewSource(long targetPos) throws IOException {\n    throw new IOException(\"Seek not supported\");\n  }\n\n  @Override\n  public synchronized int read() throws IOException {\n    if (closed) {\n      throw new IOException(\"Stream closed\");\n    }\n\n    int byteRead = wrappedStream.read();\n    if (byteRead >= 0) {\n      pos++;\n    }\n    if (stats != null && byteRead >= 0) {","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ftp/FTPInputStream.java#L44-L80","documentation":"FTPInputStream wraps a strictly sequential FTP data connection; seek(long) always throws IOException(\"Seek not supported\") because the implementation never restarts a RETR at an offset (no REST command). The position only advances via reads, and getPos() merely reports it.","triggerScenarios":"Calling FSDataInputStream.seek() on a stream from FTPFileSystem.open(path): split-based readers (MapReduce input formats), calling seek(0) to restart parsing, PositionedReadable/readFully helpers that seek internally, or format readers (Avro/Parquet) fetching footers from the end of the file.","commonSituations":"Running compute frameworks or splittable formats directly over ftp:// URLs; generic code assuming every FileSystem's streams are seekable; re-reading input by seeking back after a parse failure.","solutions":["Reopen the stream and skip forward to the offset instead of seeking (sequential skip is supported)","Copy the file to HDFS or local disk first (FileUtil.copy/distcp) and run seek-heavy code there","Restructure reading into a single forward pass (streaming parser)","Branch on fs.getUri().getScheme() and only call seek on seek-capable filesystems"],"exampleFix":"// before\ntry (FSDataInputStream in = fs.open(path)) {\n  in.seek(offset);            // IOException: Seek not supported\n  in.readFully(buf);\n}\n\n// after\ntry (FSDataInputStream in = fs.open(path)) {\n  long skipped = 0;\n  while (skipped < offset) {\n    skipped += in.skip(offset - skipped);   // forward-only positioning\n  }\n  in.readFully(buf);\n}","handlingStrategy":"fallback","validationCode":"// avoid seek() on sequential-only filesystems\nboolean seekable = !\"ftp\".equalsIgnoreCase(fs.getUri().getScheme());\nif (!seekable && targetPos != in.getPos()) {\n  // reposition by reopen + skip instead of seek\n}","typeGuard":null,"tryCatchPattern":"catch IOException from seek(), verify \"Seek not supported\", then close and reopen the stream at the required offset using skip(); keep getPos() before failing to make the resume point exact.","preventionTips":["Check the filesystem scheme before designing seek-based readers","Copy ftp:// files to HDFS/local before running splittable input formats","Track position with getPos() so any reopen can resume precisely"],"tags":["ftp","hadoop","input-stream","seek","unsupported-operation"],"backgroundTag":"seek-unsupported","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}