{"record":{"id":"1673d78f67c6f32a","repo":"apache/hadoop","slug":"mkdirs-failed-to-create-parent-tostring","errorCode":null,"errorMessage":"Mkdirs failed to create \" + parent.toString()","messagePattern":"Mkdirs failed to create \" \\+ parent\\.toString\\(\\)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java","lineNumber":645,"sourceCode":"  }\n\n  @Override\n  public FSDataOutputStream create(Path f, boolean overwrite, int bufferSize,\n    short replication, long blockSize, Progressable progress)\n    throws IOException {\n    return create(f, overwrite, true, bufferSize, replication, blockSize,\n        progress, null);\n  }\n\n  private FSDataOutputStream create(Path f, boolean overwrite,\n      boolean createParent, int bufferSize, short replication, long blockSize,\n      Progressable progress, FsPermission permission) throws IOException {\n    if (exists(f) && !overwrite) {\n      throw new FileAlreadyExistsException(\"File already exists: \" + f);\n    }\n    Path parent = f.getParent();\n    if (parent != null && !mkdirs(parent)) {\n      throw new IOException(\"Mkdirs failed to create \" + parent.toString());\n    }\n    return new FSDataOutputStream(new BufferedIOStatisticsOutputStream(\n        createOutputStreamWithMode(f, false, permission), bufferSize, true),\n        statistics);\n  }\n  \n  protected OutputStream createOutputStream(Path f, boolean append) \n      throws IOException {\n    return createOutputStreamWithMode(f, append, null);\n  }\n\n  protected OutputStream createOutputStreamWithMode(Path f, boolean append,\n      FsPermission permission) throws IOException {\n    return new LocalFSFileOutputStream(f, append, permission);\n  }\n  \n  @Override\n  public FSDataOutputStream createNonRecursive(Path f, FsPermission permission,","sourceCodeStart":627,"sourceCodeEnd":663,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java#L627-L663","documentation":"During create(), RawLocalFileSystem calls mkdirs(parent) and throws IOException('Mkdirs failed to create ...') when it returns false. The message names the parent directory. Failure means mkdirs could not create or find the parent as a directory: typically a permissions problem, a parent path occupied by a regular file (which surfaces deeper as ParentNotDirectoryException/FileAlreadyExistsException), or an unwritable ancestor.","triggerScenarios":"fs.create(\"/var/data/out/file\") where /var/data/out cannot be created because the running user lacks write permission on /var/data, or because a regular file named 'out' already occupies the path, or on unusual mounts (read-only NFS, full disk) where mkdir fails.","commonSituations":"Services running as a non-root user writing into system directories, containers with read-only volumes mounted at the target, a prior step that wrote a file where a directory tree is now expected, or disk/quota exhaustion on the local volume.","solutions":["Inspect the exact parent path from the message: ls -l the ancestors and confirm each is a directory and writable by the process user.","If a regular file occupies the parent path, remove or relocate it: rm /var/data/out (a file) then retry.","Fix permissions/ownership: chown/chmod the intended parent chain or move the output under a writable base (e.g. under the user's home or ${hadoop.tmp.dir}).","For read-only or full mounts, relocate output to a writable filesystem and free space."],"exampleFix":"# before (shell)\n$ ls -l /var/data\n-rw-r--r-- 1 root root 0 out      # regular file blocks the directory\n\n# after\n$ sudo rm /var/data/out\n$ sudo mkdir -p /var/data/out && sudo chown $USER /var/data/out","handlingStrategy":"validation","validationCode":"// pre-flight the parent chain before create()\nPath parent = p.getParent();\nif (parent != null && !fs.exists(parent)) {\n  FileStatus ancestor = firstExistingAncestor(fs, parent);\n  if (!ancestor.isDirectory()) {\n    throw new IOException(\"Ancestor \" + ancestor.getPath() + \" is a file\");\n  }\n  // writable check\n  if (!fs.getFileStatus(ancestor.getPath()).getPermission()\n        .getUserAction().implies(FsAction.WRITE)) {\n    LOG.warn(\"{} may not be writable by this user\", ancestor.getPath());\n  }\n}\nFSDataOutputStream out = fs.create(p, true);","typeGuard":null,"tryCatchPattern":"try {\n  return fs.create(p, overwrite);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Mkdirs failed\")) {\n    throw new IOException(\"Cannot create parent of \" + p\n        + \": check permissions and that no file occupies the parent path\", e);\n  }\n  throw e;\n}","preventionTips":["Verify each ancestor of the output path is a directory writable by the process user before running jobs.","Prefer output roots under user-writable bases (home, hadoop.tmp.dir).","Never let files and directory trees share a path prefix in your layout."],"tags":["hadoop","local-filesystem","mkdirs","permissions","create","parent-directory"],"backgroundTag":"parent-directory-creation-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}