{"record":{"id":"0bc515b3551767a6","repo":"apache/hadoop","slug":"the-source-and-destination-are-the-same","errorCode":null,"errorMessage":"The source {} and destination {} are the same","messagePattern":"The source (.+?) and destination (.+?) are the same","errorType":"exception","errorClass":"FileAlreadyExistsException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirRenameOp.java","lineNumber":398,"sourceCode":"   */\n  static RenameResult unprotectedRenameTo(FSDirectory fsd,\n      final INodesInPath srcIIP, final INodesInPath dstIIP, long timestamp,\n      BlocksMapUpdateInfo collectedBlocks, Options.Rename... options)\n      throws IOException {\n    assert fsd.hasWriteLock();\n    boolean overwrite = options != null\n        && Arrays.asList(options).contains(Options.Rename.OVERWRITE);\n\n    final String src = srcIIP.getPath();\n    final String dst = dstIIP.getPath();\n    final String error;\n    final INode srcInode = srcIIP.getLastINode();\n    List<INodeDirectory> srcSnapshottableDirs = new ArrayList<>();\n    validateRenameSource(fsd, srcIIP, srcSnapshottableDirs);\n\n    // validate the destination\n    if (dst.equals(src)) {\n      throw new FileAlreadyExistsException(\"The source \" + src +\n          \" and destination \" + dst + \" are the same\");\n    }\n    validateDestination(src, dst, srcInode);\n\n    if (dstIIP.length() == 1) {\n      error = \"rename destination cannot be the root\";\n      NameNode.stateChangeLog.warn(\"DIR* FSDirectory.unprotectedRenameTo: \" +\n          error);\n      throw new IOException(error);\n    }\n\n    BlockStoragePolicySuite bsps = fsd.getBlockStoragePolicySuite();\n    fsd.ezManager.checkMoveValidity(srcIIP, dstIIP);\n    final INode dstInode = dstIIP.getLastINode();\n    List<INodeDirectory> dstSnapshottableDirs = new ArrayList<>();\n    if (dstInode != null) { // Destination exists\n      validateOverwrite(src, dst, overwrite, srcInode, dstInode);\n      FSDirSnapshotOp.checkSnapshot(fsd, dstIIP, dstSnapshottableDirs);","sourceCodeStart":380,"sourceCodeEnd":416,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirRenameOp.java#L380-L416","documentation":"FileAlreadyExistsException from renameToInt when source and destination resolve to the exact same path. Rename-to-self is rejected up front during destination validation, before overwrite checks - even Options.Rename.OVERWRITE cannot make it meaningful (it would delete the source).","triggerScenarios":"`hdfs dfs -mv /a /a`; programmatic fs.rename(src, dst) where both Paths are equal after qualification (same URI, no trailing-slash difference); templated pipelines substituting identical src/dst values from config.","commonSituations":"Config-driven promotion pipelines where the source and destination variables collapse to the same value (same table rename, env-to-env copy with matching envs); path normalization differences hiding the equality from the caller but not the NameNode.","solutions":["Fix the caller to pass a genuinely different destination path.","Guard in code: compare qualified src and dst and treat equality as a no-op.","Inspect the job's configuration for miswired source/destination parameters."],"exampleFix":"// before\nfs.rename(src, dst); // src and dst qualified to the same path\n\n// after\nif (!src.makeQualified(fs.getUri(), fs.getWorkingDirectory())\n        .equals(dst.makeQualified(fs.getUri(), fs.getWorkingDirectory()))) {\n  fs.rename(src, dst);\n}","handlingStrategy":"validation","validationCode":"Path qs = src.makeQualified(fs.getUri(), fs.getWorkingDirectory());\nPath qd = dst.makeQualified(fs.getUri(), fs.getWorkingDirectory());\nif (qs.equals(qd)) {\n  return; // src == dst: nothing to do\n}\nfs.rename(src, dst);","typeGuard":null,"tryCatchPattern":"try {\n  fs.rename(src, dst);\n} catch (FileAlreadyExistsException e) {\n  if (src.makeQualified(fs.getUri(), fs.getWorkingDirectory())\n      .equals(dst.makeQualified(fs.getUri(), fs.getWorkingDirectory()))) {\n    return; // no-op, ignore\n  }\n  throw e;\n}","preventionTips":["Compare qualified (URI + working-dir resolved) paths before any rename.","Validate src/dst config pairs at job submission time."],"tags":["hdfs","rename","file-already-exists","path-validation"],"backgroundTag":"same-source-and-destination","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}