{"record":{"id":"f1cba8cabfbdd91d","repo":"apache/hadoop","slug":"item-s-parent-s-path-is-null-this-can-happen-if","errorCode":null,"errorMessage":"Item: %s parent's path is null. This can happen if mkdir is called on root, so there's no parent.","messagePattern":"Item: (.+?) parent's path is null\\. This can happen if mkdir is called on root, so there's no parent\\.","errorType":"exception","errorClass":"PathNotFoundException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Mkdir.java","lineNumber":78,"sourceCode":"    if (item.stat.isDirectory()) {\n      if (!createParents) {\n        throw new PathExistsException(item.toString());\n      }\n    } else {\n      throw new PathIsNotDirectoryException(item.toString());\n    }\n  }\n\n  @Override\n  protected void processNonexistentPath(PathData item) throws IOException {\n    if (!createParents) {\n      // check if parent exists. this is complicated because getParent(a/b/c/) returns a/b/c, but\n      // we want a/b\n      final Path itemPath = new Path(item.path.toString());\n      final Path itemParentPath = itemPath.getParent();\n\n      if(itemParentPath == null) {\n        throw new PathNotFoundException(String.format(\n            \"Item: %s parent's path is null. This can happen if mkdir is \" +\n                \"called on root, so there's no parent.\", itemPath.toString()));\n      }\n\n      if (!item.fs.exists(itemParentPath)) {\n        throw new PathNotFoundException(itemParentPath.toString());\n      }\n    }\n    if (!item.fs.mkdirs(item.path)) {\n      throw new PathIOException(item.toString());\n    }\n  }\n}\n","sourceCodeStart":60,"sourceCodeEnd":92,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Mkdir.java#L60-L92","documentation":"PathNotFoundException with a custom message thrown by Mkdir.processNonexistentPath (Mkdir.java:78): the target path does not exist (that is why processNonexistentPath runs), -p is not set, and itemPath.getParent() returned null — which happens for root-only paths like '/' or 'hdfs://nn:9000/', i.e. mkdir was invoked on the filesystem root, which by definition has no parent to validate.","triggerScenarios":"'hadoop fs -mkdir /' (or a scheme/authority-only URI) without -p, on a filesystem whose root does not report as existing so the nonexistent-path branch is taken; unusual mount roots in viewfs; programmatic calls that build a path from an empty suffix. Note: on a healthy HDFS the root exists and mkdir / fails elsewhere — hitting THIS message means the root was treated as nonexistent (often an unreachable or unformatted filesystem).","commonSituations":"Scripts looping over candidate base dirs that end up with the root string; misconfigured fs.defaultFS or an unreachable NameNode making '/' appear nonexistent; path arithmetic that strips the last component and leaves the root.","solutions":["Do not mkdir the root — create a child: 'hadoop fs -mkdir /data'","Verify the filesystem itself is reachable and formatted: 'hadoop fs -ls /' (if this fails, fix fs.defaultFS / NameNode state in core-site.xml)","If you really must run the same command generically, add -p: the parent check is skipped when createParents is set"],"exampleFix":"# before\nhadoop fs -mkdir /    # Item: / parent's path is null ...\n\n# after\nhadoop fs -mkdir /data","handlingStrategy":"validation","validationCode":"Path parent = new Path(item.path.toString()).getParent();\nif (parent == null) {\n  throw new PathNotFoundException(\n      \"Item: \" + item.path + \" parent's path is null. This can happen if mkdir \"\n      + \"is called on root, so there's no parent.\");\n}","typeGuard":"static boolean hasParent(Path p) {\n  return p.getParent() != null; // false only for root-like paths\n}","tryCatchPattern":"try {\n  fs.mkdirs(path);\n} catch (PathNotFoundException e) {\n  if (path.getParent() == null) {\n    // mkdir on root is meaningless; create a child directory instead\n  }\n}","preventionTips":["Never mkdir the filesystem root ('/' or 'scheme://authority/')","If '/' reports nonexistent, fix fs.defaultFS / NameNode reachability first","Use -p when a generic script may hit root-like paths"],"tags":["hadoop","mkdir","shell","root-path","path-not-found","argument-validation"],"backgroundTag":"path-not-found","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}