{"record":{"id":"5ece3e6f0104d4a1","repo":"apache/hadoop","slug":"parent-path-is-not-a-directory","errorCode":null,"errorMessage":"Parent path is not a directory: {} {}","messagePattern":"Parent path is not a directory: (.+?) (.+?)","errorType":"exception","errorClass":"FileAlreadyExistsException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirMkdirOp.java","lineNumber":220,"sourceCode":"            p.getUserAction().or(FsAction.WRITE_EXECUTE),\n            p.getGroupAction(),\n            p.getOtherAction()), p.getUnmasked());\n    }\n    return new PermissionStatus(perm.getUserName(), perm.getGroupName(),\n        ancestorPerm);\n  }\n\n  /**\n   * create a directory at path specified by parent\n   */\n  private static INodesInPath unprotectedMkdir(FSDirectory fsd, long inodeId,\n      INodesInPath parent, byte[] name, PermissionStatus permission,\n      List<AclEntry> aclEntries, long timestamp)\n      throws QuotaExceededException, AclException, FileAlreadyExistsException {\n    assert fsd.hasWriteLock();\n    assert parent.getLastINode() != null;\n    if (!parent.getLastINode().isDirectory()) {\n      throw new FileAlreadyExistsException(\"Parent path is not a directory: \" +\n          parent.getPath() + \" \" + DFSUtil.bytes2String(name));\n    }\n    final INodeDirectory dir = new INodeDirectory(inodeId, name, permission,\n        timestamp);\n\n    INodesInPath iip = fsd.addLastINode(parent, dir, permission.getPermission(),\n        true, Optional.empty());\n    if (iip != null && aclEntries != null) {\n      AclStorage.updateINodeAcl(dir, aclEntries, Snapshot.CURRENT_STATE_ID);\n    }\n    return iip;\n  }\n}\n\n","sourceCodeStart":202,"sourceCodeEnd":235,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirMkdirOp.java#L202-L235","documentation":"FileAlreadyExistsException from unprotectedMkdir: while creating missing ancestors during mkdir -p, an existing component of the parent chain is a file rather than a directory. The message names the offending parent path plus the child component it tried to create beneath it.","triggerScenarios":"`hdfs dfs -mkdir -p /part-file/a/b` where /part-file is a regular file; any deep mkdir where an intermediate component (not necessarily the last) is a file.","commonSituations":"Path templates where an earlier job wrote a file at a component now used as a directory (e.g., /etl/daily being both a file and a directory at different times); near-duplicate paths from case or trailing-space mismatches.","solutions":["Walk the path level by level with `hdfs dfs -ls` to find the file component, then remove or rename it.","Restructure paths so files never sit where directories are expected.","Pre-validate all existing ancestors in code before calling mkdir -p."],"exampleFix":"# before\nhdfs dfs -mkdir -p /etl/daily/2026/08/22\n# FileAlreadyExistsException: Parent path is not a directory: /etl/daily 2026\n\n# after\nhdfs dfs -mv /etl/daily /etl/daily.bak      # move the blocking file\nhdfs dfs -mkdir -p /etl/daily/2026/08/22","handlingStrategy":"validation","validationCode":"static void verifyAncestorsAreDirs(FileSystem fs, Path p) throws IOException {\n  for (Path cur = p.getParent(); cur != null && !cur.isRoot(); cur = cur.getParent()) {\n    if (fs.exists(cur) && !fs.getFileStatus(cur).isDirectory()) {\n      throw new ParentNotDirectoryException(\"File blocks the path at \" + cur);\n    }\n  }\n}\nverifyAncestorsAreDirs(fs, p);\nfs.mkdirs(p);","typeGuard":null,"tryCatchPattern":"try {\n  fs.mkdirs(p);\n} catch (FileAlreadyExistsException e) {\n  // message names the offending parent component; surface it to the user\n  throw e;\n}","preventionTips":["Never let files and directories share the same path prefix at different times.","Validate the whole ancestor chain before deep mkdir -p in provisioning code."],"tags":["hdfs","mkdir","parent-not-directory","path-conflict"],"backgroundTag":"parent-not-directory","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}