{"record":{"id":"f24bda401cc86b9f","repo":"apache/hadoop","slug":"rename-destination-parent-parent-not-found","errorCode":null,"errorMessage":"rename destination parent ${parent} not found.","messagePattern":"rename destination parent (.+?) not found\\.","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java","lineNumber":1715,"sourceCode":"      }\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        FileStatus[] list = listStatus(dst);\n        if (list != null && list.length != 0) {\n          throw new IOException(\n              \"rename cannot overwrite non empty destination directory \" + dst);\n        }\n      }\n      delete(dst, false);\n    } else {\n      final Path parent = dst.getParent();\n      final FileStatus parentStatus = getFileStatus(parent);\n      if (parentStatus == null) {\n        throw new FileNotFoundException(\"rename destination parent \" + parent\n            + \" not found.\");\n      }\n      if (!parentStatus.isDirectory()) {\n        throw new ParentNotDirectoryException(\"rename destination parent \" + parent\n            + \" is a file.\");\n      }\n    }\n    if (!rename(src, dst)) {\n      throw new IOException(\"rename from \" + src + \" to \" + dst + \" failed.\");\n    }\n  }\n\n  /**\n   * Truncate the file in the indicated path to the indicated size.\n   * <ul>\n   *   <li>Fails if path is a directory.</li>\n   *   <li>Fails if path does not exist.</li>\n   *   <li>Fails if path is not closed.</li>","sourceCodeStart":1697,"sourceCodeEnd":1733,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java#L1697-L1733","documentation":"In the deprecated options-aware rename, when the destination does not exist its parent is stat'ed; a null parent status throws FileNotFoundException('rename destination parent parent not found.'). Rename never creates destination parents - that is mkdirs' job.","triggerScenarios":"rename(src, dst) where dst's parent directory was never created or was concurrently removed - e.g. renaming into a new dated/partition subdirectory.","commonSituations":"Partitioned output layouts where the parent dir comes from an earlier step that failed; cleanup daemons racing the publish step.","solutions":["Call fs.mkdirs(dst.getParent()) before the rename","Validate parent existence in publish preconditions and fail early with context","Retry once after recreating parents if a concurrent cleaner may have interfered"],"exampleFix":"// before\nfs.rename(src, new Path(base, \"dt=2026-08-22/part\")); // parent 'dt=...' absent\n\n// after\nPath dst = new Path(base, \"dt=2026-08-22/part\");\nfs.mkdirs(dst.getParent());\nfs.rename(src, dst);","handlingStrategy":"validation","validationCode":"Path parent = dst.getParent();\nif (!fs.exists(parent)) {\n  fs.mkdirs(parent);\n}\nfs.rename(src, dst);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Create destination parents as an explicit pipeline step","Check parent existence in publish preconditions","Watch for cleanup daemons that race publish steps"],"tags":["hadoop","filesystem","rename","missing-directory"],"backgroundTag":"missing-parent-directory","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}