{"record":{"id":"2bbd92d3e519426c","repo":"apache/hadoop","slug":"mkdirs-failed-to-create","errorCode":null,"errorMessage":"Mkdirs failed to create {}","messagePattern":"Mkdirs failed to create (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/RunJar.java","lineNumber":242,"sourceCode":"        }\n      }\n      if (numOfFailedLastModifiedSet > 0) {\n        LOG.warn(\"Could not set last modfied time for {} file(s)\",\n            numOfFailedLastModifiedSet);\n      }\n    }\n  }\n\n  /**\n   * Ensure the existence of a given directory.\n   *\n   * @param dir Directory to check\n   *\n   * @throws IOException if it cannot be created and does not already exist\n   */\n  private static void ensureDirectory(File dir) throws IOException {\n    if (!dir.mkdirs() && !dir.isDirectory()) {\n      throw new IOException(\"Mkdirs failed to create \" +\n                            dir.toString());\n    }\n  }\n\n  /** Run a Hadoop job jar.  If the main class is not in the jar's manifest,\n   * then it must be provided on the command line.\n   *\n   * @param args args.\n   * @throws Throwable error.\n   */\n  public static void main(String[] args) throws Throwable {\n    new RunJar().run(args);\n  }\n\n  public void run(String[] args) throws Throwable {\n    String usage = \"RunJar jarFile [mainClass] args...\";\n\n    if (args.length < 1) {","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/RunJar.java#L224-L260","documentation":"RunJar, the class behind the `hadoop jar` command, unpacks a job jar into a working directory before invoking its main class. ensureDirectory() calls File.mkdirs() on that directory; if mkdirs() returns false AND the path is not already a directory, it throws IOException(\"Mkdirs failed to create <dir>\"). The job jar never runs because its unpack target cannot be created — almost always a permission conflict, a regular file occupying the path, or a full/read-only filesystem.","triggerScenarios":"Running `hadoop jar app.jar ...` when the unjar working directory (created under java.io.tmpdir / the temp area) cannot be created: parent directory lacks write permission for the launching user, a regular file already exists at the exact directory path, the filesystem is full, read-only (container overlayfs), or SELinux/NFS root-squash denies the mkdir.","commonSituations":"Running as an unprivileged user against a locked-down /tmp; a leftover file from a previously crashed run occupying the target path; Docker/Kubernetes containers with read-only root filesystems; disk exhaustion during CI; NFS mounts with squashed privileges.","solutions":["Inspect the path named in the message: create it manually with `mkdir -p <dir>` to surface the real OS error (permission denied, not a directory, read-only FS)","If a regular file sits at that path, delete or rename it","Give the launcher a writable temp area: run with -Djava.io.tmpdir=/var/tmp/$USER (and/or set hadoop.tmp.dir to a writable location)","Check the filesystem: `df -h <dir>` for space and `touch <dir>/probe` for writability","Re-run `hadoop jar` as a user with write access to the temp directory"],"exampleFix":"# before: fails with Mkdirs failed to create /tmp/hadoop-unjar123\nhadoop jar app.jar com.example.Main\n# diagnose the real error\nls -ld /tmp/hadoop-unjar123; mkdir -p /tmp/hadoop-unjar123\n# after: point RunJar at a writable temp dir\nhadoop jar app.jar com.example.Main -Djava.io.tmpdir=/var/tmp/$USER  # or: export HADOOP_OPTS=\"$HADOOP_OPTS -Djava.io.tmpdir=/var/tmp/$USER\"","handlingStrategy":"validation","validationCode":"File tmp = new File(System.getProperty(\"java.io.tmpdir\"));\nFile unjar = new File(tmp, \"hadoop-unjar\");\nif (unjar.exists() && !unjar.isDirectory())\n  throw new IOException(\"path occupied by a regular file: \" + unjar);\nif (!unjar.exists() && !unjar.mkdirs())\n  throw new IOException(\"cannot create \" + unjar + \" — check permissions/disk\");","typeGuard":null,"tryCatchPattern":"try {\n  new RunJar().run(args);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Mkdirs failed to create\")) {\n    // report the named directory; fix permissions/occupying file and relaunch\n  }\n  throw e;\n}","preventionTips":["Give the hadoop-launching user a writable temp directory policy (java.io.tmpdir / hadoop.tmp.dir)","Clean stale unjar directories after crashed runs","In containers, mount writable emptyDir/tmpfs at the temp location"],"tags":["hadoop","runjar","mkdirs","filesystem","permissions","temp-dir"],"backgroundTag":"directory-creation-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}