{"record":{"id":"dbcd3976a9dfb9a9","repo":"apache/hadoop","slug":"invalid-path-s-s","errorCode":null,"errorMessage":"Invalid Path \"%s\" : %s","messagePattern":"Invalid Path \"(.+?)\" : (.+?)","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":65,"sourceCode":"      Pattern.compile(RegistryInternalConstants.VALID_PATH_ENTRY_PATTERN);\n\n  private static final Pattern USER_NAME =\n      Pattern.compile(\"/users/([a-z][a-z0-9-.]*)\");\n\n  /**\n   * Validate ZK path with the path itself included in\n   * the exception text\n   * @param path path to validate\n   * @return the path parameter\n   * @throws InvalidPathnameException if the pathname is invalid.\n   */\n  public static String validateZKPath(String path) throws\n      InvalidPathnameException {\n    try {\n      PathUtils.validatePath(path);\n\n    } 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 + \"\\\"\");","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-registry/src/main/java/org/apache/hadoop/registry/client/binding/RegistryPathUtils.java#L47-L83","documentation":"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.","triggerScenarios":"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.","commonSituations":"Concatenating user names or service names into paths without sanitizing; passing URL-style or Windows-style paths; empty service names coming from configuration defaults.","solutions":["Normalize before use: build paths with RegistryUtils/RegistryPathUtils join helpers so segments are always well-formed","Trim input, guarantee a single leading '/', strip trailing slashes, and collapse duplicate slashes","Pre-validate at the trust boundary with the same PathUtils.validatePath call and reject bad input early with a clear message"],"exampleFix":"// before\nString path = userRoot + service; // \"registry/yarn\" no leading slash\nRegistryPathUtils.validateZKPath(path);\n\n// after\nString path = RegistryPathUtils.join(userRoot, service.toLowerCase()); // \"/registry/yarn\"\nRegistryPathUtils.validateZKPath(path);","handlingStrategy":"validation","validationCode":"private static String normalizeRegistryPath(String p) {\n  String path = p == null ? \"\" : p.trim();\n  if (path.isEmpty()) throw new IllegalArgumentException(\"empty registry path\");\n  if (!path.startsWith(\"/\")) path = \"/\" + path;\n  while (path.endsWith(\"/\") && path.length() > 1) path = path.substring(0, path.length() - 1);\n  return path.replaceAll(\"/+/\", \"/\");\n}\n// then: RegistryPathUtils.validateZKPath(normalizeRegistryPath(input));","typeGuard":null,"tryCatchPattern":"try {\n  RegistryPathUtils.validateZKPath(path);\n} catch (InvalidPathnameException e) {\n  throw new IllegalArgumentException(\"Rejecting user-supplied path \" + path, e);\n}","preventionTips":["Build registry paths only with RegistryUtils/RegistryPathUtils join helpers, never string concatenation","Reject empty and relative paths at the API boundary before they reach the registry","Never let '.', '..', '//' or trailing slashes into stored paths"],"tags":["registry","zookeeper","path","validation"],"backgroundTag":"invalid-zookeeper-path","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}