{"record":{"id":"0c8b67448826fbd4","repo":"apache/hadoop","slug":"path-is-relative","errorCode":null,"errorMessage":"Path is relative","messagePattern":"Path is relative","errorType":"exception","errorClass":"HadoopIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java","lineNumber":94,"sourceCode":"\n  private static final long serialVersionUID = 0xad00f;\n\n  private URI uri; // a hierarchical uri\n\n  /**\n   * Test whether this Path uses a scheme and is relative.\n   * Pathnames with scheme and relative path are illegal.\n   */\n  void checkNotSchemeWithRelative() {\n    if (toUri().isAbsolute() && !isUriPathAbsolute()) {\n      throw new HadoopIllegalArgumentException(\n          \"Unsupported name: has scheme but relative path-part\");\n    }\n  }\n\n  void checkNotRelative() {\n    if (!isAbsolute() && toUri().getScheme() == null) {\n      throw new HadoopIllegalArgumentException(\"Path is relative\");\n    }\n  }\n\n  /**\n   * Return a version of the given Path without the scheme information.\n   *\n   * @param path the source Path\n   * @return a copy of this Path without the scheme information\n   */\n  public static Path getPathWithoutSchemeAndAuthority(Path path) {\n    // This code depends on Path.toString() to remove the leading slash before\n    // the drive specification on Windows.\n    Path newPath = path.isUriPathAbsolute() ?\n      new Path(null, null, path.toUri().getPath()) :\n      path;\n    return newPath;\n  }\n","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java#L76-L112","documentation":"Path.checkNotRelative() rejects paths that are neither absolute nor scheme-qualified: !isAbsolute() with no URI scheme (e.g. 'input/data.txt') throws HadoopIllegalArgumentException('Path is relative'). FileSystem.verifyPath (FileSystem.java:431) and FileContext (FileContext.java:328) call it, so relative paths fail at the first filesystem API that must resolve them.","triggerScenarios":"new Path(\"input/file.txt\") handed to FileSystem.open/getFileStatus/etc. — verifyPath throws because a bare relative path cannot be pinned to a filesystem without qualification.","commonSituations":"Relative paths from CLI arguments or config values, code ported from java.io.File assumptions, unit tests passing plain strings, tools run from different working directories.","solutions":["Qualify before use: path.makeQualified(fs.getUri(), fs.getWorkingDir()) or new Path(\"/abs/path\")","Store fully-qualified URIs (scheme://authority/path) in configuration files","Validate user input with an isAbsolute()/scheme predicate and reject or normalize early"],"exampleFix":"// before\nfs.open(new Path(\"input/data.txt\"));\n// after\nPath p = new Path(\"input/data.txt\").makeQualified(fs.getUri(), fs.getWorkingDir());\nfs.open(p);","handlingStrategy":"validation","validationCode":"Path q = (p.isAbsolute() || p.toUri().getScheme() != null)\n    ? p : p.makeQualified(fs.getUri(), fs.getWorkingDir());","typeGuard":"static boolean isRelativeWithoutScheme(Path p) {\n  return !p.isAbsolute() && p.toUri().getScheme() == null;\n}","tryCatchPattern":"try {\n  fs.open(p);\n} catch (HadoopIllegalArgumentException e) {\n  /* relative path: qualify against the default FS working dir and retry */\n}","preventionTips":["Qualify user-supplied paths with makeQualified before FS APIs","Store fully-qualified URIs in configuration","Assert in tests that all configured paths are absolute or schemed"],"tags":["path","relative-path","uri","validation","hadoop"],"backgroundTag":"relative-path-not-allowed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}