{"record":{"id":"cb8f41853b24828e","repo":"apache/hadoop","slug":"invalid-path-element-s","errorCode":null,"errorMessage":"Invalid Path element \"%s\"","messagePattern":"Invalid Path element \"(.+?)\"","errorType":"exception","errorClass":"InvalidPathnameException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-registry/src/main/java/org/apache/hadoop/registry/client/binding/RegistryPathUtils.java","lineNumber":82,"sourceCode":"    } catch (IllegalArgumentException e) {\n      throw new InvalidPathnameException(path,\n          \"Invalid Path \\\"\" + path + \"\\\" : \" + e, e);\n    }\n    return path;\n  }\n\n  /**\n   * Validate ZK path as valid for a DNS hostname.\n   * @param path path to validate\n   * @return the path parameter\n   * @throws InvalidPathnameException if the pathname is invalid.\n   */\n  public static String validateElementsAsDNS(String path) throws\n      InvalidPathnameException {\n    List<String> splitpath = split(path);\n    for (String fragment : splitpath) {\n      if (!PATH_ENTRY_VALIDATION_PATTERN.matcher(fragment).matches()) {\n        throw new InvalidPathnameException(path,\n            \"Invalid Path element \\\"\" + fragment + \"\\\"\");\n      }\n    }\n    return path;\n  }\n\n  /**\n   * Create a full path from the registry root and the supplied subdir\n   * @param path path of operation\n   * @return an absolute path\n   * @throws InvalidPathnameException if the path is invalid\n   */\n  public static String createFullPath(String base, String path) throws\n      InvalidPathnameException {\n    Preconditions.checkArgument(path != null, \"null path\");\n    Preconditions.checkArgument(base != null, \"null path\");\n    return validateZKPath(join(base, path));\n  }","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-registry/src/main/java/org/apache/hadoop/registry/client/binding/RegistryPathUtils.java#L64-L100","documentation":"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.","triggerScenarios":"Paths containing elements like 'YARN' (uppercase), 'my_service' (underscore), 'web-api-' (trailing hyphen), or 'a.b' (dot inside one segment instead of separate segments).","commonSituations":"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.","solutions":["Lowercase and sanitize each element before building registry paths: replace '_' and '.' with '-', then re-validate","Split multi-level names into separate path elements ('/services/yarn' not '/services/yar.n')","Validate element-wise at input time with the same pattern and reject invalid names with an actionable message"],"exampleFix":"// before\nString path = RegistryPathUtils.join(\"/services\", \"YARN_ATS\");\nRegistryPathUtils.validateElementsAsDNS(path); // -> Invalid Path element \"YARN_ATS\"\n\n// after\nString element = \"YARN_ATS\".toLowerCase().replace('_', '-'); // \"yarn-ats\"\nString path = RegistryPathUtils.join(\"/services\", element);\nRegistryPathUtils.validateElementsAsDNS(path);","handlingStrategy":"validation","validationCode":"private static final Pattern DNS_LABEL = Pattern.compile(\"[a-z0-9]([a-z0-9-]*[a-z0-9])?\");\n\nstatic String sanitizeElement(String raw) {\n  String e = raw.trim().toLowerCase().replace('_', '-').replace('.', '-');\n  if (!DNS_LABEL.matcher(e).matches()) {\n    throw new IllegalArgumentException(\"Invalid registry path element: \" + raw);\n  }\n  return e;\n}\nString path = RegistryPathUtils.join(root, sanitizeElement(serviceName));","typeGuard":null,"tryCatchPattern":"try {\n  RegistryPathUtils.validateElementsAsDNS(path);\n} catch (InvalidPathnameException e) {\n  throw new IllegalArgumentException(\"Service name must be a lowercase DNS label: \" + name, e);\n}","preventionTips":["Lowercase and sanitize user-supplied names ('_' and '.' -> '-') before building registry paths","Enforce DNS-label naming for services at registration time, not at read time","Represent hierarchy with separate path elements, never dots inside one element"],"tags":["registry","dns","path","naming","validation"],"backgroundTag":"invalid-dns-name","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}