apache/hadoop · error · PathNotFoundException

No parent of %s

Error message

No parent of %s

What it means

RegistryPathUtils.parentOf splits a path into elements and returns the parent; at the root ('/' or '' — split yields zero elements) there is no parent, so it throws PathNotFoundException ('No parent of <path>'). Note split("") and split("/") both return an empty list.

Source

Thrown at hadoop-common-project/hadoop-registry/src/main/java/org/apache/hadoop/registry/client/binding/RegistryPathUtils.java:189

      // empty path. Return ""
      return "";
    } else {
      return splits.get(splits.size() - 1);
    }
  }

  /**
   * Get the parent of a path
   * @param path path to look at
   * @return the parent path
   * @throws PathNotFoundException if the path was at root.
   */
  public static String parentOf(String path) throws PathNotFoundException {
    List<String> elements = split(path);

    int size = elements.size();
    if (size == 0) {
      throw new PathNotFoundException("No parent of " + path);
    }
    if (size == 1) {
      return "/";
    }
    elements.remove(size - 1);
    StringBuilder parent = new StringBuilder(path.length());
    for (String element : elements) {
      parent.append("/");
      parent.append(element);
    }
    return parent.toString();
  }

  /**
   * Perform any formatting for the registry needed to convert
   * non-simple-DNS elements
   * @param element element to encode
   * @return an encoded string

View on GitHub (pinned to 2add963021)

Solutions

  1. Terminate the walk at root explicitly: while (!"/".equals(path)) { ...; path = RegistryPathUtils.parentOf(path); }
  2. Guard the call: if RegistryPathUtils.split(path).isEmpty(), handle the root case before calling parentOf
  3. Catch PathNotFoundException from parentOf as the 'reached root' signal and stop the walk

Example fix

// before
String p = path;
while (p != null) {
  visit(p);
  p = RegistryPathUtils.parentOf(p); // throws at "/"
}

// after
String p = path;
while (p != null && !RegistryPathUtils.split(p).isEmpty()) {
  visit(p);
  p = RegistryPathUtils.parentOf(p);
}
Defensive patterns

Strategy: validation

Validate before calling

String current = path;
while (!RegistryPathUtils.split(current).isEmpty()) { // empty at "/" or ""
  visit(current);
  current = RegistryPathUtils.parentOf(current);
}

Try / catch

try {
  parent = RegistryPathUtils.parentOf(path);
} catch (PathNotFoundException e) {
  // path was root — no parent exists; stop walking up
  return Optional.empty();
}

Prevention

When it happens

Trigger: Walking up the tree with parentOf in a loop and calling it once more when the path is already '/'; calling parentOf("/") or parentOf("") directly; loop conditions like while (path != null) instead of while (!path.equals("/")).

Common situations: Recursive delete/list algorithms over registry subtrees; code ported from filesystem utilities that expect parent-of-root to return null instead of throwing.

Related errors


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