{"record":{"id":"e0ead54885cb7c8b","repo":"GoogleContainerTools/jib","slug":"cannot-create-absoluteunixpath-from-non-absolute-p","errorCode":null,"errorMessage":"Cannot create AbsoluteUnixPath from non-absolute Path: ${path}","messagePattern":"Cannot create AbsoluteUnixPath from non-absolute Path: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"jib-build-plan/src/main/java/com/google/cloud/tools/jib/api/buildplan/AbsoluteUnixPath.java","lineNumber":60,"sourceCode":"   */\n  public static AbsoluteUnixPath get(String unixPath) {\n    if (!unixPath.startsWith(\"/\")) {\n      throw new IllegalArgumentException(\"Path does not start with forward slash (/): \" + unixPath);\n    }\n\n    return new AbsoluteUnixPath(UnixPathParser.parse(unixPath));\n  }\n\n  /**\n   * Gets a new {@link AbsoluteUnixPath} from a {@link Path}. The {@code path} must be absolute\n   * (indicated by a non-null {@link Path#getRoot}).\n   *\n   * @param path the absolute {@link Path} to convert to an {@link AbsoluteUnixPath}.\n   * @return a new {@link AbsoluteUnixPath}\n   */\n  public static AbsoluteUnixPath fromPath(Path path) {\n    if (path.getRoot() == null) {\n      throw new IllegalArgumentException(\n          \"Cannot create AbsoluteUnixPath from non-absolute Path: \" + path);\n    }\n\n    List<String> pathComponents = new ArrayList<>(path.getNameCount());\n    path.forEach(component -> pathComponents.add(component.toString()));\n    return new AbsoluteUnixPath(pathComponents);\n  }\n\n  /** Path components after the file system root. This should always match {@link #unixPath}. */\n  private final List<String> pathComponents;\n\n  /**\n   * Unix-style path, in absolute form. Does not end with trailing slash, except for the file system\n   * root ({@code /}). This should always match {@link #pathComponents}.\n   */\n  private final String unixPath;\n\n  private AbsoluteUnixPath(List<String> pathComponents) {","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/GoogleContainerTools/jib/blob/fb949e2676afbbd7dd7a1ef61e20251931325654/jib-build-plan/src/main/java/com/google/cloud/tools/jib/api/buildplan/AbsoluteUnixPath.java#L42-L78","documentation":"AbsoluteUnixPath.fromPath() converts a java.nio.file.Path into an AbsoluteUnixPath, but the source Path must have a root (be absolute). It throws IllegalArgumentException when getRoot() returns null, i.e. the Path is relative, since the result must denote an absolute container path.","triggerScenarios":"Calling fromPath(new File(\"relative/dir\").toPath()) or any Path constructed without a filesystem root.","commonSituations":"Relative workspace/local paths (e.g. Paths.get(\"build/libs/app.jar\")) passed where a container-absolute path is required; forgetting that local relative paths have no root.","solutions":["Call toAbsolutePath() on the Path before passing it to fromPath()","Ensure the path is resolved against a base directory: baseDir.resolve(relativePath)","If the value should be relative in the container, use RelativeUnixPath instead"],"exampleFix":"// before\nAbsoluteUnixPath p = AbsoluteUnixPath.fromPath(Paths.get(\"build/libs\"));\n// after\nAbsoluteUnixPath p = AbsoluteUnixPath.fromPath(Paths.get(\"build/libs\").toAbsolutePath());","handlingStrategy":"validation","validationCode":"if (path.getRoot() == null) path = path.toAbsolutePath();","typeGuard":"boolean isAbsolutePath(Path p) { return p != null && p.getRoot() != null; }","tryCatchPattern":"try { AbsoluteUnixPath p = AbsoluteUnixPath.fromPath(path); } catch (IllegalArgumentException e) { AbsoluteUnixPath p = AbsoluteUnixPath.fromPath(path.toAbsolutePath()); }","preventionTips":["Call toAbsolutePath() on any locally constructed Path before conversion","Avoid File(\"relative\").toPath() without resolving against a base dir","Document that container paths must be absolute in your config schema"],"tags":["jib","path-validation","illegal-argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"fb949e2676afbbd7dd7a1ef61e20251931325654","analyzedAt":"2026-09-06T14:04:09.491Z","contentChangedAt":"2026-09-06T14:04:09.491Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}