GoogleContainerTools/jib · error · IllegalArgumentException

Cannot create AbsoluteUnixPath from non-absolute Path: ${pat

Error message

Cannot create AbsoluteUnixPath from non-absolute Path: ${path}

What it means

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.

Source

Thrown at jib-build-plan/src/main/java/com/google/cloud/tools/jib/api/buildplan/AbsoluteUnixPath.java:60

   */
  public static AbsoluteUnixPath get(String unixPath) {
    if (!unixPath.startsWith("/")) {
      throw new IllegalArgumentException("Path does not start with forward slash (/): " + unixPath);
    }

    return new AbsoluteUnixPath(UnixPathParser.parse(unixPath));
  }

  /**
   * Gets a new {@link AbsoluteUnixPath} from a {@link Path}. The {@code path} must be absolute
   * (indicated by a non-null {@link Path#getRoot}).
   *
   * @param path the absolute {@link Path} to convert to an {@link AbsoluteUnixPath}.
   * @return a new {@link AbsoluteUnixPath}
   */
  public static AbsoluteUnixPath fromPath(Path path) {
    if (path.getRoot() == null) {
      throw new IllegalArgumentException(
          "Cannot create AbsoluteUnixPath from non-absolute Path: " + path);
    }

    List<String> pathComponents = new ArrayList<>(path.getNameCount());
    path.forEach(component -> pathComponents.add(component.toString()));
    return new AbsoluteUnixPath(pathComponents);
  }

  /** Path components after the file system root. This should always match {@link #unixPath}. */
  private final List<String> pathComponents;

  /**
   * Unix-style path, in absolute form. Does not end with trailing slash, except for the file system
   * root ({@code /}). This should always match {@link #pathComponents}.
   */
  private final String unixPath;

  private AbsoluteUnixPath(List<String> pathComponents) {

View on GitHub (pinned to fb949e2676)

Solutions

  1. Call toAbsolutePath() on the Path before passing it to fromPath()
  2. Ensure the path is resolved against a base directory: baseDir.resolve(relativePath)
  3. If the value should be relative in the container, use RelativeUnixPath instead

Example fix

// before
AbsoluteUnixPath p = AbsoluteUnixPath.fromPath(Paths.get("build/libs"));
// after
AbsoluteUnixPath p = AbsoluteUnixPath.fromPath(Paths.get("build/libs").toAbsolutePath());
Defensive patterns

Strategy: validation

Validate before calling

if (path.getRoot() == null) path = path.toAbsolutePath();

Type guard

boolean isAbsolutePath(Path p) { return p != null && p.getRoot() != null; }

Try / catch

try { AbsoluteUnixPath p = AbsoluteUnixPath.fromPath(path); } catch (IllegalArgumentException e) { AbsoluteUnixPath p = AbsoluteUnixPath.fromPath(path.toAbsolutePath()); }

Prevention

When it happens

Trigger: Calling fromPath(new File("relative/dir").toPath()) or any Path constructed without a filesystem root.

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of GoogleContainerTools/jib@fb949e2676 (2026-09-06). Data as JSON: /api/errors/e0ead54885cb7c8b. Report an issue: GitHub.