{"record":{"id":"c31439a099657973","repo":"apache/hadoop","slug":"relative-paths-not-allowed-path","errorCode":null,"errorMessage":"relative paths not allowed:{path}","messagePattern":"relative paths not allowed:(.+?)","errorType":"validation","errorClass":"InvalidPathException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java","lineNumber":378,"sourceCode":"  /**\n   * Check that a Path belongs to this FileSystem.\n   * \n   * If the path is fully qualified URI, then its scheme and authority\n   * matches that of this file system. Otherwise the path must be \n   * slash-relative name.\n   * @param path the path.\n   * @throws InvalidPathException if the path is invalid\n   */\n  public void checkPath(Path path) {\n    URI uri = path.toUri();\n    String thatScheme = uri.getScheme();\n    String thatAuthority = uri.getAuthority();\n    if (thatScheme == null) {\n      if (thatAuthority == null) {\n        if (path.isUriPathAbsolute()) {\n          return;\n        }\n        throw new InvalidPathException(\"relative paths not allowed:\" + \n            path);\n      } else {\n        throw new InvalidPathException(\n            \"Path without scheme with non-null authority:\" + path);\n      }\n    }\n    String thisScheme = this.getUri().getScheme();\n    String thisHost = this.getUri().getHost();\n    String thatHost = uri.getHost();\n    \n    // Schemes and hosts must match.\n    // Allow for null Authority for file:///\n    if (!thisScheme.equalsIgnoreCase(thatScheme) ||\n       (thisHost != null && \n            !thisHost.equalsIgnoreCase(thatHost)) ||\n       (thisHost == null && thatHost != null)) {\n      throw new InvalidPathException(\"Wrong FS: \" + path + \", expected: \"\n          + this.getUri());","sourceCodeStart":360,"sourceCodeEnd":396,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java#L360-L396","documentation":"AbstractFileSystem.checkPath rejects a Path that has no scheme, no authority, and a non-absolute path part (does not begin with '/'). AbstractFileSystem methods operate on absolute paths bound to that FS instance; FileContext normally qualifies relative paths for you (fixRelativePart + working directory), but direct calls on an AbstractFileSystem bypass that step and hit this InvalidPathException.","triggerScenarios":"Calling AbstractFileSystem methods directly (getUriPath, getFileStatus, create, ...) with new Path(\"data/file\"); passing a path built from raw user input that lacks a leading slash; a custom FS framework invoking afs operations without going through FileContext.","commonSituations":"Unit tests or internal tooling that grab the AbstractFileSystem instead of FileContext; paths read from config files or CLI args without a leading '/'; refactors that replaced FileContext calls with direct AFS calls.","solutions":["Make the path absolute: new Path(\"/data/file\") or prefix with Path.SEPARATOR","Route operations through FileContext, whose fixRelativePart resolves relative paths against the working directory","Qualify the path first: path = path.makeQualified(defaultFS, workingDir)"],"exampleFix":"// before\nafs.getUriPath(new Path(\"input/part-0\")); // relative paths not allowed\n\n// after\nafs.getUriPath(new Path(\"/user/me/input/part-0\"));","handlingStrategy":"validation","validationCode":"Path p = input;\nif (p.toUri().getScheme() == null && p.toUri().getAuthority() == null && !p.isUriPathAbsolute()) {\n  p = new Path(Path.SEPARATOR + p); // or route through FileContext which fixes relative paths\n}","typeGuard":null,"tryCatchPattern":"catch (InvalidPathException e) { if (e.getMessage().startsWith(\"relative paths not allowed\")) { p = p.makeQualified(defaultFs, wd); /* retry */ } else throw e; }","preventionTips":["Prefer FileContext over direct AbstractFileSystem calls; it qualifies relative paths via fixRelativePart","Normalize user-supplied paths to absolute at the input boundary","Assert path.isUriPathAbsolute() in tests that hit AbstractFileSystem directly"],"tags":["hadoop","path","validation","filesystem"],"backgroundTag":"relative-path-not-allowed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}