apache/hadoop · error · PathNotFoundException

Item: %s parent's path is null. This can happen if mkdir is

Error message

Item: %s parent's path is null. This can happen if mkdir is called on root, so there's no parent.

What it means

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.

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Mkdir.java:78

    if (item.stat.isDirectory()) {
      if (!createParents) {
        throw new PathExistsException(item.toString());
      }
    } else {
      throw new PathIsNotDirectoryException(item.toString());
    }
  }

  @Override
  protected void processNonexistentPath(PathData item) throws IOException {
    if (!createParents) {
      // check if parent exists. this is complicated because getParent(a/b/c/) returns a/b/c, but
      // we want a/b
      final Path itemPath = new Path(item.path.toString());
      final Path itemParentPath = itemPath.getParent();

      if(itemParentPath == null) {
        throw new PathNotFoundException(String.format(
            "Item: %s parent's path is null. This can happen if mkdir is " +
                "called on root, so there's no parent.", itemPath.toString()));
      }

      if (!item.fs.exists(itemParentPath)) {
        throw new PathNotFoundException(itemParentPath.toString());
      }
    }
    if (!item.fs.mkdirs(item.path)) {
      throw new PathIOException(item.toString());
    }
  }
}

View on GitHub (pinned to 2add963021)

Solutions

  1. Do not mkdir the root — create a child: 'hadoop fs -mkdir /data'
  2. Verify the filesystem itself is reachable and formatted: 'hadoop fs -ls /' (if this fails, fix fs.defaultFS / NameNode state in core-site.xml)
  3. If you really must run the same command generically, add -p: the parent check is skipped when createParents is set

Example fix

# before
hadoop fs -mkdir /    # Item: / parent's path is null ...

# after
hadoop fs -mkdir /data
Defensive patterns

Strategy: validation

Validate before calling

Path parent = new Path(item.path.toString()).getParent();
if (parent == null) {
  throw new PathNotFoundException(
      "Item: " + item.path + " parent's path is null. This can happen if mkdir "
      + "is called on root, so there's no parent.");
}

Type guard

static boolean hasParent(Path p) {
  return p.getParent() != null; // false only for root-like paths
}

Try / catch

try {
  fs.mkdirs(path);
} catch (PathNotFoundException e) {
  if (path.getParent() == null) {
    // mkdir on root is meaningless; create a child directory instead
  }
}

Prevention

When it happens

Trigger: '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).

Common situations: 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.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/f1cba8cabfbdd91d. Report an issue: GitHub.