{"record":{"id":"bcff9a96006f57fa","repo":"apache/hadoop","slug":"source-and-destination-must-both-be-director","errorCode":null,"errorMessage":"Source {} and destination {} must both be directories","messagePattern":"Source (.+?) and destination (.+?) must both be directories","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirRenameOp.java","lineNumber":577,"sourceCode":"    }\n\n    if (FSDirectory.isExactReservedName(src)\n        || FSDirectory.isExactReservedName(dst)) {\n      error = \"Cannot rename to or from /.reserved\";\n      throw new InvalidPathException(error);\n    }\n  }\n\n  private static void validateOverwrite(\n      String src, String dst, boolean overwrite, INode srcInode, INode dstInode)\n      throws IOException {\n    String error;// It's OK to rename a file to a symlink and vice versa\n    if (dstInode.isDirectory() != srcInode.isDirectory()) {\n      error = \"Source \" + src + \" and destination \" + dst\n          + \" must both be directories\";\n      NameNode.stateChangeLog.warn(\"DIR* FSDirectory.unprotectedRenameTo: \"\n          + error);\n      throw new IOException(error);\n    }\n    if (!overwrite) { // If destination exists, overwrite flag must be true\n      error = \"rename destination \" + dst + \" already exists\";\n      NameNode.stateChangeLog.warn(\"DIR* FSDirectory.unprotectedRenameTo: \"\n          + error);\n      throw new FileAlreadyExistsException(error);\n    }\n    if (dstInode.isDirectory()) {\n      final ReadOnlyList<INode> children = dstInode.asDirectory()\n          .getChildrenList(Snapshot.CURRENT_STATE_ID);\n      if (!children.isEmpty()) {\n        error = \"rename destination directory is not empty: \" + dst;\n        NameNode.stateChangeLog.warn(\"DIR* FSDirectory.unprotectedRenameTo: \"\n            + error);\n        throw new IOException(error);\n      }\n    }\n  }","sourceCodeStart":559,"sourceCodeEnd":595,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirRenameOp.java#L559-L595","documentation":"Error \"Source {} and destination {} must both be directories\" thrown in apache/hadoop.","triggerScenarios":"Renaming with the OVERWRITE/TO_TRASH options where either the source or the destination is not a directory while both must be directories.","commonSituations":"See trigger scenarios.","solutions":["When renaming with snapshot diff restrictions, ensure both source and destination are directories.","Rename the directory instead of mixing a file with a directory path."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}