{"record":{"id":"248024b5000d0d12","repo":"GoogleContainerTools/jib","slug":"path-starts-with-forward-slash-relativepath","errorCode":null,"errorMessage":"Path starts with forward slash (/): ${relativePath}","messagePattern":"Path starts with forward slash \\(/\\): (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"jib-build-plan/src/main/java/com/google/cloud/tools/jib/api/buildplan/RelativeUnixPath.java","lineNumber":41,"sourceCode":"\n/**\n * Represents a Unix-style path in relative form (does not start at the file system root {@code /}).\n *\n * <p>This class is immutable and thread-safe.\n */\n@Immutable\npublic class RelativeUnixPath {\n\n  /**\n   * Gets a new {@link RelativeUnixPath} from a Unix-style path in relative form. The {@code path}\n   * must be relative (does not begin with a leading slash {@code /}).\n   *\n   * @param relativePath the relative path\n   * @return a new {@link RelativeUnixPath}\n   */\n  public static RelativeUnixPath get(String relativePath) {\n    if (relativePath.startsWith(\"/\")) {\n      throw new IllegalArgumentException(\"Path starts with forward slash (/): \" + relativePath);\n    }\n\n    return new RelativeUnixPath(UnixPathParser.parse(relativePath));\n  }\n\n  private final List<String> pathComponents;\n\n  /** Instantiate with {@link #get}. */\n  private RelativeUnixPath(List<String> pathComponents) {\n    this.pathComponents = pathComponents;\n  }\n\n  /**\n   * Gets the relative Unix path this represents, in a list of components.\n   *\n   * @return the relative path this represents, in a list of components\n   */\n  List<String> getRelativePathComponents() {","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/GoogleContainerTools/jib/blob/fb949e2676afbbd7dd7a1ef61e20251931325654/jib-build-plan/src/main/java/com/google/cloud/tools/jib/api/buildplan/RelativeUnixPath.java#L23-L59","documentation":"RelativeUnixPath represents a Unix path that must be relative. Its get() factory throws IllegalArgumentException when the string starts with '/', because an absolute path contradicts the type's invariant.","triggerScenarios":"Calling RelativeUnixPath.get(\"/app/libs\") or any string with a leading slash.","commonSituations":"Mixing up AbsoluteUnixPath and RelativeUnixPath when configuring layer paths or extraction targets; copying an absolute container path into a relative-path field.","solutions":["Remove the leading slash and any root component before calling get()","Use AbsoluteUnixPath.get() instead if the path is genuinely absolute"],"exampleFix":"// before\nRelativeUnixPath p = RelativeUnixPath.get(\"/app/libs\");\n// after\nRelativeUnixPath p = RelativeUnixPath.get(\"app/libs\");","handlingStrategy":"validation","validationCode":"if (path == null || path.startsWith(\"/\")) throw new IllegalArgumentException(\"path must be relative: \" + path);","typeGuard":"boolean isRelativeUnixPath(String p) { return p != null && !p.startsWith(\"/\"); }","tryCatchPattern":"try { RelativeUnixPath p = RelativeUnixPath.get(path); } catch (IllegalArgumentException e) { p = RelativeUnixPath.get(path.substring(1)); }","preventionTips":["Use AbsoluteUnixPath for absolute paths and RelativeUnixPath only for sub-paths","Strip leading slashes when converting config values to relative paths","Add a comment/schema note that this field forbids leading '/'"],"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-14T00:17:10.932Z"}