{"record":{"id":"cfc5fcd65ff30ded","repo":"apache/hadoop","slug":"the-source-src-and-destination-dst-are-the-sam","errorCode":null,"errorMessage":"The source {src} and destination {dst} are the same","messagePattern":"The source (.+?) and destination (.+?) are the same","errorType":"exception","errorClass":"FileAlreadyExistsException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java","lineNumber":863,"sourceCode":"   * @throws UnresolvedLinkException unresolved link exception.\n   * @throws IOException raised on errors performing I/O.\n   */\n  public void renameInternal(final Path src, final Path dst,\n      boolean overwrite) throws AccessControlException,\n      FileAlreadyExistsException, FileNotFoundException,\n      ParentNotDirectoryException, UnresolvedLinkException, IOException {\n    // Default implementation deals with overwrite in a non-atomic way\n    final FileStatus srcStatus = getFileLinkStatus(src);\n\n    FileStatus dstStatus;\n    try {\n      dstStatus = getFileLinkStatus(dst);\n    } catch (IOException e) {\n      dstStatus = null;\n    }\n    if (dstStatus != null) {\n      if (dst.equals(src)) {\n        throw new FileAlreadyExistsException(\n            \"The source \"+src+\" and destination \"+dst+\" are the same\");\n      }\n      if (srcStatus.isSymlink() && dst.equals(srcStatus.getSymlink())) {\n        throw new FileAlreadyExistsException(\n            \"Cannot rename symlink \"+src+\" to its target \"+dst);\n      }\n      // It's OK to rename a file to a symlink and vice versa\n      if (srcStatus.isDirectory() != dstStatus.isDirectory()) {\n        throw new IOException(\"Source \" + src + \" and destination \" + dst\n            + \" must both be directories\");\n      }\n      if (!overwrite) {\n        throw new FileAlreadyExistsException(\"Rename destination \" + dst\n            + \" already exists.\");\n      }\n      // Delete the destination that is a file or an empty directory\n      if (dstStatus.isDirectory()) {\n        RemoteIterator<FileStatus> list = listStatusIterator(dst);","sourceCodeStart":845,"sourceCodeEnd":881,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java#L845-L881","documentation":"The default (non-atomic) rename-with-overwrite in AbstractFileSystem first stats both ends; when the destination exists and dst.equals(src) (Path equality is URI equality), it throws FileAlreadyExistsException — renaming an entry onto itself is refused as a no-op. A sibling branch also rejects renaming a symlink onto its own target.","triggerScenarios":"rename(a, a) with a existing; loops that compute a destination which degenerates to the source path (\"move to same location\"); dst produced by makeQualified/makeQualified-equivalent that ends up with the identical URI as src.","commonSituations":"Archive/compaction jobs whose filter selects nothing so the computed destination equals the input; output directory configured equal to input directory; distcp-style tooling where src and dst resolve to the same qualified path; renames inside loops with per-row destinations.","solutions":["Skip the operation when the fully-qualified paths are equal: if (fc.makeQualified(src).equals(fc.makeQualified(dst))) return;","Fix the destination computation so it genuinely differs (distinct name, subdirectory, or timestamp suffix)","Validate src != dst at the API boundary of your move/rename helpers and report it as a no-op, not an error"],"exampleFix":"// before\nfc.rename(src, dst, Rename.OVERWRITE); // src and dst resolve to the same path\n\n// after\nif (!fc.makeQualified(src).equals(fc.makeQualified(dst))) {\n  fc.rename(src, dst, Rename.OVERWRITE);\n}","handlingStrategy":"validation","validationCode":"Path qs = fc.makeQualified(src), qd = fc.makeQualified(dst);\nif (qs.equals(qd)) {\n  return; // moving onto itself: treat as no-op\n}\nfc.rename(src, dst, Rename.OVERWRITE);","typeGuard":null,"tryCatchPattern":"catch (FileAlreadyExistsException e) { if (srcQualified.equals(dstQualified)) { /* no-op move: skip */ } else throw e; }","preventionTips":["Compare fully-qualified src and dst before every rename/move","Ensure destination computation always produces a different path (suffix, subdirectory)","Guard archive/compaction loops where filters can select nothing and degenerate dst to src"],"tags":["hadoop","rename","file-already-exists","filesystem","validation"],"backgroundTag":"rename-source-equals-destination","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}