{"record":{"id":"43fffa7b35d9f4d7","repo":"apache/hadoop","slug":"parent-path-is-not-a-directory-parent","errorCode":null,"errorMessage":"Parent path is not a directory: \" + parent","messagePattern":"Parent path is not a directory: \" \\+ parent","errorType":"exception","errorClass":"ParentNotDirectoryException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java","lineNumber":911,"sourceCode":"  }\n\n  @Override\n  public boolean mkdirs(Path f, FsPermission permission) throws IOException {\n    return mkdirsWithOptionalPermission(f, permission);\n  }\n\n  private boolean mkdirsWithOptionalPermission(Path f, FsPermission permission)\n      throws IOException {\n    if(f == null) {\n      throw new IllegalArgumentException(\"mkdirs path arg is null\");\n    }\n    Path parent = f.getParent();\n    File p2f = pathToFile(f);\n    File parent2f = null;\n    if(parent != null) {\n      parent2f = pathToFile(parent);\n      if(parent2f != null && parent2f.exists() && !parent2f.isDirectory()) {\n        throw new ParentNotDirectoryException(\"Parent path is not a directory: \"\n            + parent);\n      }\n    }\n    if (p2f.exists() && !p2f.isDirectory()) {\n      throw new FileAlreadyExistsException(\"Destination exists\" +\n              \" and is not a directory: \" + p2f.getCanonicalPath());\n    }\n    return (parent == null || parent2f.exists() || mkdirs(parent)) &&\n      (mkOneDirWithMode(f, p2f, permission) || p2f.isDirectory());\n  }\n  \n  \n  @Override\n  public Path getHomeDirectory() {\n    return this.makeQualified(new Path(System.getProperty(\"user.home\")));\n  }\n\n  /**","sourceCodeStart":893,"sourceCodeEnd":929,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java#L893-L929","documentation":"mkdirsWithOptionalPermission throws ParentNotDirectoryException when the target's parent path exists on local disk but is a regular file, so directory creation cannot proceed. mkdirs can create missing directories but cannot replace a file with a directory. The message names the offending parent path.","triggerScenarios":"fs.mkdirs(\"/data/out/subdir\") where /data/out is a regular file; interleaved operations where create() wrote a file at a path later used as a directory prefix; flattening/nesting path schemes between versions of an app.","commonSituations":"Path scheme changes (previously /data-out as a file, now /data/out/... as a tree) without cleanup, tests that create files then reuse prefixes as directories, symlink to a file occupying the parent slot, or config changed to nest paths under an existing file location.","solutions":["Inspect the parent named in the message: ls -l shows a regular file where a directory is required.","Remove or relocate the blocking file: rm /data/out (or mv it elsewhere), then retry mkdirs.","Pick a non-colliding prefix in configuration so files and directory trees never share a path.","If concurrent create/mkdir may race, serialize with a lock or pre-create the directory layout once at startup."],"exampleFix":"# before\n$ ls -l /data/out\n-rw-r--r-- 1 app app 1024 out    # file blocks parent dir\nfs.mkdirs(new Path(\"/data/out/subdir\")); // ParentNotDirectoryException\n\n# after\n$ rm /data/out\nfs.mkdirs(new Path(\"/data/out/subdir\")); // succeeds","handlingStrategy":"validation","validationCode":"// ensure no ancestor of the target is a regular file\nPath t = target;\nwhile (t.getParent() != null) {\n  t = t.getParent();\n  if (fs.exists(t) && !fs.getFileStatus(t).isDirectory()) {\n    throw new IOException(\"Ancestor \" + t + \" is a file; cannot mkdir under it\");\n  }\n}\nfs.mkdirs(target);","typeGuard":null,"tryCatchPattern":"try {\n  fs.mkdirs(dir);\n} catch (ParentNotDirectoryException e) {\n  throw new IOException(\"Path layout conflict under \" + dir\n      + \": remove the file occupying the parent path\", e);\n}","preventionTips":["Design path layouts so directory prefixes never collide with file paths.","Check ancestor types before mkdir when reusing paths across app versions.","Resolve symlinks before deciding layout; a link to a file blocks mkdir."],"tags":["hadoop","local-filesystem","mkdirs","parent-not-directory","path-conflict"],"backgroundTag":"parent-not-a-directory","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}