apache/hadoop · error · InvalidPathnameException

Invalid Path "%s" : %s

Error message

Invalid Path "%s" : %s

What it means

RegistryPathUtils.validateZKPath delegates to ZooKeeper/Curator PathUtils.validatePath and converts any IllegalArgumentException into InvalidPathnameException ('Invalid Path "<path>" : <cause>'). Valid ZK paths must be non-null, start with '/', contain no empty segments ('//'), no '.' or '..', no trailing '/', and no illegal characters such as NUL.

Source

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

      Pattern.compile(RegistryInternalConstants.VALID_PATH_ENTRY_PATTERN);

  private static final Pattern USER_NAME =
      Pattern.compile("/users/([a-z][a-z0-9-.]*)");

  /**
   * Validate ZK path with the path itself included in
   * the exception text
   * @param path path to validate
   * @return the path parameter
   * @throws InvalidPathnameException if the pathname is invalid.
   */
  public static String validateZKPath(String path) throws
      InvalidPathnameException {
    try {
      PathUtils.validatePath(path);

    } catch (IllegalArgumentException e) {
      throw new InvalidPathnameException(path,
          "Invalid Path \"" + path + "\" : " + e, e);
    }
    return path;
  }

  /**
   * Validate ZK path as valid for a DNS hostname.
   * @param path path to validate
   * @return the path parameter
   * @throws InvalidPathnameException if the pathname is invalid.
   */
  public static String validateElementsAsDNS(String path) throws
      InvalidPathnameException {
    List<String> splitpath = split(path);
    for (String fragment : splitpath) {
      if (!PATH_ENTRY_VALIDATION_PATTERN.matcher(fragment).matches()) {
        throw new InvalidPathnameException(path,
            "Invalid Path element \"" + fragment + "\"");

View on GitHub (pinned to 2add963021)

Solutions

  1. Normalize before use: build paths with RegistryUtils/RegistryPathUtils join helpers so segments are always well-formed
  2. Trim input, guarantee a single leading '/', strip trailing slashes, and collapse duplicate slashes
  3. Pre-validate at the trust boundary with the same PathUtils.validatePath call and reject bad input early with a clear message

Example fix

// before
String path = userRoot + service; // "registry/yarn" no leading slash
RegistryPathUtils.validateZKPath(path);

// after
String path = RegistryPathUtils.join(userRoot, service.toLowerCase()); // "/registry/yarn"
RegistryPathUtils.validateZKPath(path);
Defensive patterns

Strategy: validation

Validate before calling

private static String normalizeRegistryPath(String p) {
  String path = p == null ? "" : p.trim();
  if (path.isEmpty()) throw new IllegalArgumentException("empty registry path");
  if (!path.startsWith("/")) path = "/" + path;
  while (path.endsWith("/") && path.length() > 1) path = path.substring(0, path.length() - 1);
  return path.replaceAll("/+/", "/");
}
// then: RegistryPathUtils.validateZKPath(normalizeRegistryPath(input));

Try / catch

try {
  RegistryPathUtils.validateZKPath(path);
} catch (InvalidPathnameException e) {
  throw new IllegalArgumentException("Rejecting user-supplied path " + path, e);
}

Prevention

When it happens

Trigger: Building registry paths from unnormalized input: '' (empty), 'services/yarn' (missing leading slash), '/registry//name', '/registry/name/' (trailing slash), '/a/../b', or paths containing spaces or control characters.

Common situations: Concatenating user names or service names into paths without sanitizing; passing URL-style or Windows-style paths; empty service names coming from configuration defaults.

Related errors


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