{"record":{"id":"87ce9f52eb01d3cd","repo":"apache/hadoop","slug":"path-part-s-from-uri-p-is-not-a-valid-filename","errorCode":null,"errorMessage":"Path part {s} from URI {p} is not a valid filename.","messagePattern":"Path part (.+?) from URI (.+?) is not a valid filename\\.","errorType":"validation","errorClass":"InvalidPathException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java","lineNumber":427,"sourceCode":"          + \", expected: \"\n          + this.getUri()\n          + \" with port=\" + thisPort);\n    }\n  }\n  \n  /**\n   * Get the path-part of a pathname. Checks that URI matches this file system\n   * and that the path-part is a valid name.\n   * \n   * @param p path\n   * \n   * @return path-part of the Path p\n   */\n  public String getUriPath(final Path p) {\n    checkPath(p);\n    String s = p.toUri().getPath();\n    if (!isValidName(s)) {\n      throw new InvalidPathException(\"Path part \" + s + \" from URI \" + p\n          + \" is not a valid filename.\");\n    }\n    return s;\n  }\n  \n  /**\n   * Make the path fully qualified to this file system\n   * @param path the path.\n   * @return the qualified path\n   */\n  public Path makeQualified(Path path) {\n    checkPath(path);\n    return path.makeQualified(this.getUri(), null);\n  }\n  \n  /**\n   * Some file systems like LocalFileSystem have an initial workingDir\n   * that is used as the starting workingDir. For other file systems","sourceCodeStart":409,"sourceCodeEnd":445,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java#L409-L445","documentation":"AbstractFileSystem.getUriPath calls checkPath and then validates the URI path part with isValidName, whose default rules (AbstractFileSystem.java:111) reject any path component equal to \"..\" or \".\" or containing a colon ':'. Hadoop Path normalization keeps \"..\" components, so unnormalized parents and colon-bearing filenames surface here as InvalidPathException.","triggerScenarios":"A path containing \"..\" segments (new Path(\"/a/../b\") is kept as-is), a stray \".\" component, or a filename with ':' such as \"backup:2024-01-01\" or Windows-style \"C:\" fragments; any FileContext operation that ends in getUriPath on such a path.","commonSituations":"Filenames generated from timestamps containing colons; user-supplied file names not sanitized; porting Windows paths; symlink-heavy code where \"..\" is expected to resolve late; note file systems may override isValidName with different rules.","solutions":["Sanitize file name components: strip/replace ':' (e.g. '_' for '_' + timestamp with '-' separators)","Resolve \"..\" and \".\" components before the call (e.g. new Path(path.toUri().normalize()) or your own resolution), since Path will not do it for you","Pre-check with afs.isValidName(path.toUri().getPath()) and reject bad input early at the API boundary"],"exampleFix":"// before\nString name = \"log:\" + Instant.now(); // colon in component\nafs.getUriPath(new Path(\"/logs/\" + name)); // Path part ... is not a valid filename\n\n// after\nString name = \"log-\" + Instant.now().toString().replace(':', '-');\nafs.getUriPath(new Path(\"/logs/\" + name));","handlingStrategy":"validation","validationCode":"String pathPart = p.toUri().getPath();\nif (!afs.isValidName(pathPart)) {\n  // resolve '..'/'.' and replace ':' in components before use\n  pathPart = pathPart.replace(\":\", \"_\");\n  p = new Path(p.toUri().getScheme(), p.toUri().getAuthority(), pathPart);\n}","typeGuard":null,"tryCatchPattern":"catch (InvalidPathException e) { if (e.getMessage().startsWith(\"Path part\")) { /* sanitize the offending component and retry */ } else throw e; }","preventionTips":["Sanitize user-supplied filenames (especially ':' from timestamps) at the API boundary","Remember Hadoop Path does not resolve '..' — normalize before filesystem calls","Pre-check with isValidName when the target FS uses HDFS-style rules"],"tags":["hadoop","path","filename","validation","hdfs"],"backgroundTag":"invalid-path-characters","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}