apache/hadoop · error · InvalidPathnameException

Invalid Path element "%s"

Error message

Invalid Path element "%s"

What it means

validateElementsAsDNS checks every segment of a registry path against the DNS-label pattern '([a-z0-9]|[a-z0-9][a-z0-9-]*[a-z0-9])': lowercase letters, digits and interior hyphens only. Segments with uppercase letters, underscores, dots, spaces, or leading/trailing hyphens raise InvalidPathnameException naming the offending element.

Source

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

    } 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 + "\"");
      }
    }
    return path;
  }

  /**
   * Create a full path from the registry root and the supplied subdir
   * @param path path of operation
   * @return an absolute path
   * @throws InvalidPathnameException if the path is invalid
   */
  public static String createFullPath(String base, String path) throws
      InvalidPathnameException {
    Preconditions.checkArgument(path != null, "null path");
    Preconditions.checkArgument(base != null, "null path");
    return validateZKPath(join(base, path));
  }

View on GitHub (pinned to 2add963021)

Solutions

  1. Lowercase and sanitize each element before building registry paths: replace '_' and '.' with '-', then re-validate
  2. Split multi-level names into separate path elements ('/services/yarn' not '/services/yar.n')
  3. Validate element-wise at input time with the same pattern and reject invalid names with an actionable message

Example fix

// before
String path = RegistryPathUtils.join("/services", "YARN_ATS");
RegistryPathUtils.validateElementsAsDNS(path); // -> Invalid Path element "YARN_ATS"

// after
String element = "YARN_ATS".toLowerCase().replace('_', '-'); // "yarn-ats"
String path = RegistryPathUtils.join("/services", element);
RegistryPathUtils.validateElementsAsDNS(path);
Defensive patterns

Strategy: validation

Validate before calling

private static final Pattern DNS_LABEL = Pattern.compile("[a-z0-9]([a-z0-9-]*[a-z0-9])?");

static String sanitizeElement(String raw) {
  String e = raw.trim().toLowerCase().replace('_', '-').replace('.', '-');
  if (!DNS_LABEL.matcher(e).matches()) {
    throw new IllegalArgumentException("Invalid registry path element: " + raw);
  }
  return e;
}
String path = RegistryPathUtils.join(root, sanitizeElement(serviceName));

Try / catch

try {
  RegistryPathUtils.validateElementsAsDNS(path);
} catch (InvalidPathnameException e) {
  throw new IllegalArgumentException("Service name must be a lowercase DNS label: " + name, e);
}

Prevention

When it happens

Trigger: Paths containing elements like 'YARN' (uppercase), 'my_service' (underscore), 'web-api-' (trailing hyphen), or 'a.b' (dot inside one segment instead of separate segments).

Common situations: Service names derived from user names or hostnames — underscores are legal in many systems but not DNS labels; uppercase names copied from documentation; embedding dots where the registry expects separate path elements.

Related errors


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