{"record":{"id":"b9864ff08948c6ca","repo":"apache/hadoop","slug":"source-path-s-does-not-exist","errorCode":null,"errorMessage":"Source path %s does not exist","messagePattern":"Source path (.+?) does not exist","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/sftp/SFTPFileSystem.java","lineNumber":476,"sourceCode":"   * @param channel\n   * @param src\n   * @param dst\n   * @return rename successful?\n   * @throws IOException\n   */\n  private boolean rename(ChannelSftp channel, Path src, Path dst)\n      throws IOException {\n    Path workDir;\n    try {\n      workDir = new Path(channel.pwd());\n    } catch (SftpException e) {\n      throw new IOException(e);\n    }\n    Path absoluteSrc = makeAbsolute(workDir, src);\n    Path absoluteDst = makeAbsolute(workDir, dst);\n\n    if (!exists(channel, absoluteSrc)) {\n      throw new IOException(String.format(E_SPATH_NOTEXIST, src));\n    }\n    if (exists(channel, absoluteDst)) {\n      throw new IOException(String.format(E_DPATH_EXIST, dst));\n    }\n    boolean renamed = true;\n    try {\n      final String previousCwd = channel.pwd();\n      channel.cd(\"/\");\n      channel.rename(src.toUri().getPath(), dst.toUri().getPath());\n      channel.cd(previousCwd);\n    } catch (SftpException e) {\n      renamed = false;\n    }\n    return renamed;\n  }\n\n  @Override\n  public void initialize(URI uriInfo, Configuration conf) throws IOException {","sourceCodeStart":458,"sourceCodeEnd":494,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/sftp/SFTPFileSystem.java#L458-L494","documentation":"Thrown by SFTPFileSystem.rename (private overload) when the source path of a rename over the sftp:// scheme does not exist on the SFTP server. Existence is verified with an lstat against makeAbsolute(workDir, src), where workDir is the SFTP channel's pwd(). Unlike most FileSystem implementations that return false for a missing source, the SFTP adapter throws a plain IOException.","triggerScenarios":"Calling fs.rename(src, dst) on an sftp:// URI when exists(channel, absoluteSrc) is false: the source was typo'd, already moved/deleted, or a relative path was resolved against the SFTP server's login directory (channel pwd) instead of the directory the caller assumed.","commonSituations":"Using relative paths like data/file when the channel's pwd is the user's SFTP home directory; the file was consumed by another process between the check and the rename; code ported from LocalFileSystem or HDFS that expects rename() to return false instead of throwing; logged in as a different SFTP user whose home differs.","solutions":["Check fs.exists(src) before calling rename and treat a missing source as a no-op instead of an error.","Use fully-qualified absolute sftp:// paths (e.g. sftp://host/export/data/file) so resolution never depends on the channel working directory.","If you rely on the boolean contract of FileSystem.rename, wrap the call in try/catch (IOException) and map the 'Source path ... does not exist' failure to a false return."],"exampleFix":"// before\nfs.rename(new Path(\"data/file.csv\"), new Path(\"data/file.done\")); // relative -> resolved against SFTP pwd\n\n// after\nPath src = new Path(\"sftp://myhost/export/data/file.csv\");\nPath dst = new Path(\"sftp://myhost/export/data/file.done\");\nif (fs.exists(src)) {\n  fs.rename(src, dst);\n}","handlingStrategy":"validation","validationCode":"if (!fs.exists(src)) {\n  LOG.warn(\"rename skipped, source missing: {}\", src);\n  return false;\n}","typeGuard":null,"tryCatchPattern":"try {\n  fs.rename(src, dst);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"does not exist\")) {\n    // source vanished: treat as already moved\n  } else {\n    throw e;\n  }\n}","preventionTips":["Always use fully-qualified sftp://host/absolute/path URIs for rename operands.","Call fs.exists(src) immediately before rename; do not cache the result across long delays.","Do not port boolean-return assumptions from other FileSystems — SFTPFileSystem throws instead."],"tags":["sftp","rename","path-not-found","hadoop","filesystem"],"backgroundTag":"source-path-not-found","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}