{"record":{"id":"11cbfa4bfff9ae38","repo":"apache/hadoop","slug":"missing-parent-f-11cbfa","errorCode":null,"errorMessage":"Missing parent:${f}","messagePattern":"Missing parent:(.+?)","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java","lineNumber":1402,"sourceCode":"   * This a temporary method added to support the transition from FileSystem\n   * to FileContext for user applications.\n   *\n   * @param f the path.\n   * @param absolutePermission permission.\n   * @param createParent create parent.\n   * @throws IOException IO failure.\n   */\n  @Deprecated\n  protected void primitiveMkdir(Path f, FsPermission absolutePermission,\n                    boolean createParent)\n    throws IOException {\n\n    if (!createParent) { // parent must exist.\n      // since the this.mkdirs makes parent dirs automatically\n      // we must throw exception if parent does not exist.\n      final FileStatus stat = getFileStatus(f.getParent());\n      if (stat == null) {\n        throw new FileNotFoundException(\"Missing parent:\" + f);\n      }\n      if (!stat.isDirectory()) {\n        throw new ParentNotDirectoryException(\"parent is not a dir\");\n      }\n      // parent does exist - go ahead with mkdir of leaf\n    }\n    // Default impl is to assume that permissions do not matter and hence\n    // calling the regular mkdirs is good enough.\n    // FSs that implement permissions should override this.\n    if (!this.mkdirs(f, absolutePermission)) {\n      throw new IOException(\"mkdir of \"+ f + \" failed\");\n    }\n  }\n\n  /**\n   * Opens an FSDataOutputStream at the indicated Path with write-progress\n   * reporting. Same as create(), except fails if parent directory doesn't\n   * already exist.","sourceCodeStart":1384,"sourceCodeEnd":1420,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java#L1384-L1420","documentation":"primitiveMkdir(f, permission, createParent=false) is the deprecated helper behind non-recursive creates. When createParent is false it stats f.getParent() first; implementations whose getFileStatus returns null for absent paths (instead of throwing) reach the explicit FileNotFoundException('Missing parent: f'). It is the 'parent must already exist' contract made loud.","triggerScenarios":"Calling primitiveMkdir with createParent=false (including the deprecated 2-arg overload that forwards false) on a path whose parent directory chain does not exist.","commonSituations":"Non-recursive create flows that assume an earlier step already made the parent; a concurrent job deleting the parent between an exists() check and the mkdir; custom FileSystems that return null from getFileStatus for missing paths.","solutions":["Create the parent chain first: fs.mkdirs(f.getParent())","Or use fs.mkdirs(f) / pass createParent=true so parents are created automatically","If you implement a FileSystem, keep getFileStatus/primitiveMkdir semantics consistent (throw rather than return null)"],"exampleFix":"// before\nfs.primitiveMkdir(dst, FsPermission.getDefault(), false); // parent may be absent\n\n// after\nfs.mkdirs(dst.getParent());\nfs.primitiveMkdir(dst, FsPermission.getDefault(), false);","handlingStrategy":"validation","validationCode":"Path parent = f.getParent();\nif (!fs.exists(parent)) {\n  fs.mkdirs(parent);\n}\nfs.primitiveMkdir(f, perm, false);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer fs.mkdirs(f) in application code","Create parent trees as an explicit pipeline step before non-recursive creates","Re-check parent existence right before the call in racy environments"],"tags":["hadoop","filesystem","mkdir","missing-directory","deprecated-api"],"backgroundTag":"missing-parent-directory","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}