{"record":{"id":"6453e8aa1c5acf32","repo":"apache/hadoop","slug":"mkdir-of-f-failed","errorCode":null,"errorMessage":"mkdir of ${f} failed","messagePattern":"mkdir of (.+?) failed","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java","lineNumber":1413,"sourceCode":"    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.\n   * @param f the file name to open\n   * @param overwrite if a file with this name already exists, then if true,\n   * the file will be overwritten, and if false an error will be thrown.\n   * @param bufferSize the size of the buffer to be used.\n   * @param replication required block replication for the file.\n   * @param blockSize block size\n   * @param progress the progress reporter\n   * @throws IOException IO failure\n   * @see #setPermission(Path, FsPermission)\n   * @return output stream.\n   */","sourceCodeStart":1395,"sourceCodeEnd":1431,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java#L1395-L1431","documentation":"The tail of primitiveMkdir: after preconditions pass it calls this.mkdirs(f, permission) and treats a false return as IOException('mkdir of f failed'). mkdirs returns false with no detail, so the real cause - usually an existing FILE at f or a permission problem on the parent - must be found by checking those directly.","triggerScenarios":"mkdirs(f, permission) returning false: f already exists as a file, the effective user lacks write permission on the parent in the backing store, or a store-level error surfaced as a boolean false.","commonSituations":"Job rerun writing over an old file-shaped output; HDFS permissions for an unauthenticated/impersonated user under /user; object-store or custom filesystems mapping auth errors to false.","solutions":["Check what currently sits at f via fs.getFileStatus(f): if a file, delete it or pick another name","Verify write permission on the parent directory for the current user (and kinit for Kerberos clusters)","Prefer fs.mkdirs(f) after an explicit exists() check so the false path is distinguishable"],"exampleFix":"// before\nfs.primitiveMkdir(f, FsPermission.getDefault(), true); // IOException: mkdir of f failed\n\n// after\nif (fs.exists(f) && !fs.getFileStatus(f).isDirectory()) {\n  fs.delete(f, false); // stale file blocks the mkdir\n}\nboolean ok = fs.mkdirs(f);","handlingStrategy":"validation","validationCode":"if (fs.exists(f) && !fs.getFileStatus(f).isDirectory()) {\n  fs.delete(f, false); // stale file blocks the mkdir\n}\nif (!fs.exists(f.getParent())) {\n  fs.mkdirs(f.getParent());\n}\nboolean ok = fs.mkdirs(f);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clean or version output paths per run","Run as a user with write access to the target parent","With Kerberos, ensure a valid TGT before filesystem calls"],"tags":["hadoop","filesystem","mkdir","permission-denied","file-exists"],"backgroundTag":"mkdir-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}