{"record":{"id":"b909af2c34e5d981","repo":"apache/hadoop","slug":"invalid-dfs-directory-name-0","errorCode":null,"errorMessage":"Invalid DFS directory name {0}","messagePattern":"Invalid DFS directory name (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/client/HttpFSFileSystem.java","lineNumber":832,"sourceCode":"          .getBytes(StandardCharsets.UTF_8);\n    }\n    // Parse the remainingEntries boolean into hasMore\n    final long remainingEntries = (Long) listing.get(REMAINING_ENTRIES_JSON);\n    final boolean hasMore = remainingEntries > 0 ? true : false;\n    return new DirectoryEntries(statuses, newToken, hasMore);\n  }\n\n  /**\n   * Set the current working directory for the given file system. All relative\n   * paths will be resolved relative to it.\n   *\n   * @param newDir new directory.\n   */\n  @Override\n  public void setWorkingDirectory(Path newDir) {\n    String result = newDir.toUri().getPath();\n    if (!DFSUtilClient.isValidName(result)) {\n      throw new IllegalArgumentException(\n          \"Invalid DFS directory name \" + result);\n    }\n    workingDir = newDir;\n  }\n\n  /**\n   * Get the current working directory for the given file system\n   *\n   * @return the directory pathname\n   */\n  @Override\n  public Path getWorkingDirectory() {\n    if (workingDir == null) {\n      workingDir = getHomeDirectory();\n    }\n    return workingDir;\n  }\n","sourceCodeStart":814,"sourceCodeEnd":850,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/client/HttpFSFileSystem.java#L814-L850","documentation":"HttpFSFileSystem.setWorkingDirectory() validates the candidate directory with DFSUtilClient.isValidName(), which rejects relative paths and any path containing ':', '//', or '.'/'..' components. When validation fails it throws IllegalArgumentException (unchecked) with the offending path, and the working directory is left unchanged. This mirrors HDFS name rules on the WebHDFS client because relative paths must resolve against a DFS-legal working directory.","triggerScenarios":"fs.setWorkingDirectory(new Path(\"data/warehouse\")) (relative), new Path(\"hdfs://nn/user\") (contains ':' in authority when fed as path), new Path(\"/a//b\") (empty component), or new Path(\"/a/./b\") / \"../x\" constructed from raw user input.","commonSituations":"Code ported from LocalFileSystem where a relative cwd is accepted; building a Path from unvalidated CLI/env input; passing a fully-qualified URI form Path to a method that expects an absolute DFS path.","solutions":["Pass an absolute normalized path: new Path(\"/user/me/data/warehouse\")","Normalize before calling: path.makeQualified(fs.getUri(), fs.getWorkingDirectory()) then validate","Strip scheme/authority first when you hold a qualified path: new Path(path.toUri().getPath())","Validate with DFSUtilClient.isValidName(path.toUri().getPath()) and surface a clear error to the caller before touching the FileSystem"],"exampleFix":"// before\nfs.setWorkingDirectory(new Path(\"data/warehouse\"));\n// after\nPath wd = new Path(\"/user/me/data/warehouse\");\nif (!DFSUtilClient.isValidName(wd.toUri().getPath())) {\n  throw new IllegalArgumentException(\"Invalid working directory: \" + wd);\n}\nfs.setWorkingDirectory(wd);","handlingStrategy":"validation","validationCode":"Path candidate = new Path(rawInput).makeQualified(fs.getUri(), fs.getWorkingDirectory());\nif (!org.apache.hadoop.hdfs.DFSUtilClient.isValidName(candidate.toUri().getPath())) {\n  throw new IllegalArgumentException(\"Refusing invalid DFS working directory: \" + rawInput);\n}\nfs.setWorkingDirectory(candidate);","typeGuard":"static boolean isValidDfsWorkingDir(Path p) {\n  String s = p.toUri().getPath();\n  return s != null && s.startsWith(\"/\") && org.apache.hadoop.hdfs.DFSUtilClient.isValidName(s);\n}","tryCatchPattern":"try {\n  fs.setWorkingDirectory(dir);\n} catch (IllegalArgumentException e) {\n  Path qualified = new Path(dir.toUri().getPath()).makeQualified(fs.getUri(), fs.getWorkingDirectory());\n  fs.setWorkingDirectory(qualified); // one normalization retry, then fail loudly\n}","preventionTips":["Never pass raw user/env input as a working directory; normalize with makeQualified first","Prefer absolute paths starting with '/' in all configuration that ends up as cwd","Unit-test path handling with inputs containing ':', '//', '.', '..'"],"tags":["webhdfs","httpfs","path-validation","working-directory","illegalargument"],"backgroundTag":"invalid-path-name","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}