{"record":{"id":"75e889cb35f80439","repo":"apache/hadoop","slug":"rename-destination-parent-is-a-file","errorCode":null,"errorMessage":"rename destination parent {} is a file.","messagePattern":"rename destination parent (.+?) is a file\\.","errorType":"exception","errorClass":"ParentNotDirectoryException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirRenameOp.java","lineNumber":430,"sourceCode":"    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);\n    }\n\n    INode dstParent = dstIIP.getINode(-2);\n    if (dstParent == null) {\n      error = \"rename destination parent \" + dst + \" not found.\";\n      NameNode.stateChangeLog.warn(\"DIR* FSDirectory.unprotectedRenameTo: \" +\n          error);\n      throw new FileNotFoundException(error);\n    }\n    if (!dstParent.isDirectory()) {\n      error = \"rename destination parent \" + dst + \" is a file.\";\n      NameNode.stateChangeLog.warn(\"DIR* FSDirectory.unprotectedRenameTo: \" +\n          error);\n      throw new ParentNotDirectoryException(error);\n    }\n\n    validateNestSnapshot(fsd, src,\n            dstParent.asDirectory(), srcSnapshottableDirs);\n    checkUnderSameSnapshottableRoot(fsd, srcIIP, dstIIP);\n\n    // Ensure dst has quota to accommodate rename\n    verifyFsLimitsForRename(fsd, srcIIP, dstIIP);\n    Pair<Optional<QuotaCounts>, Optional<QuotaCounts>> quotaPair =\n        verifyQuotaForRename(fsd, srcIIP, dstIIP);\n\n    RenameOperation tx = new RenameOperation(fsd, srcIIP, dstIIP, quotaPair);\n\n    boolean undoRemoveSrc = true;\n    tx.removeSrc();\n\n    boolean undoRemoveDst = false;\n    long removedNum = 0;","sourceCodeStart":412,"sourceCodeEnd":448,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirRenameOp.java#L412-L448","documentation":"ParentNotDirectoryException when the destination's parent exists but is a regular file - a file cannot contain children, so the destination name is unreachable. This is checked immediately after the parent-not-found case, under the same destination validation.","triggerScenarios":"`hdfs dfs -mv /src /somefile/child` where /somefile is a file; destination built as parentPath + '/' + name where parentPath actually denotes a file; extension handling that leaves the file name in the parent slot.","commonSituations":"String-built destinations that confuse the parent component; paths where a file shadows an intended directory; templating bugs in ingest jobs.","solutions":["Choose a destination whose parent is a directory; verify with `hdfs dfs -test -d <parent>`.","Remove or rename the blocking file if it is stale.","Use Path.getParent()/Path suffix composition instead of string concatenation."],"exampleFix":"# before\nhdfs dfs -mv /staging/part /out.bin/part   # /out.bin is a file\n\n# after\nhdfs dfs -mv /staging/part /out-dir/part   # or mkdir -p /out-dir first","handlingStrategy":"type-guard","validationCode":"Path parent = dst.getParent();\nif (fs.exists(parent) && !fs.getFileStatus(parent).isDirectory()) {\n  throw new ParentNotDirectoryException(parent + \" is a file; choose a directory parent\");\n}\nfs.rename(src, dst);","typeGuard":"static boolean parentIsDirectory(FileSystem fs, Path p) throws IOException {\n  Path parent = p.getParent();\n  return parent == null || parent.isRoot()\n      || !fs.exists(parent) || fs.getFileStatus(parent).isDirectory();\n}","tryCatchPattern":"try {\n  fs.rename(src, dst);\n} catch (ParentNotDirectoryException e) {\n  // the message names the file acting as parent; fix dst construction and retry\n  throw e;\n}","preventionTips":["Build destinations with Path(parent, name) instead of string concatenation.","Test -d the destination parent in shell scripts before mv."],"tags":["hdfs","rename","parent-not-directory","destination"],"backgroundTag":"parent-not-directory","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}