{"record":{"id":"43a60a331aa0fd54","repo":"apple/pkl","slug":"missingpathinpackageuri","errorCode":"missingPathInPackageUri","errorMessage":"missingPathInPackageUri","messagePattern":"missingPathInPackageUri","errorType":"error_code","errorClass":"URISyntaxException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/packages/PackageUri.java","lineNumber":61,"sourceCode":"\n  public PackageUri(URI uri) throws URISyntaxException {\n    if (uri.isOpaque()) {\n      throw new URISyntaxException(\n          uri.toString(), ErrorMessages.create(\"invalidModuleUriMissingSlash\", uri, \"package\"));\n    }\n    var scheme = uri.getScheme();\n    if (scheme == null || !(scheme.equals(\"package\") || scheme.equals(\"projectpackage\"))) {\n      throw new URISyntaxException(\n          uri.toString(), ErrorMessages.create(\"invalidSchemeInPackageUri\", scheme));\n    }\n    var authority = uri.getAuthority();\n    if (authority == null || authority.isEmpty()) {\n      throw new URISyntaxException(\n          uri.toString(), ErrorMessages.create(\"missingAuthorityInPackageUri\", uri));\n    }\n    var path = uri.getPath();\n    if (path == null || path.isEmpty()) {\n      throw new URISyntaxException(\n          uri.toString(), ErrorMessages.create(\"missingPathInPackageUri\", uri));\n    }\n    // reject `..` segments, percent-encoded or not\n    for (var segment : path.split(\"/\", -1)) {\n      if (segment.equals(\"..\")) {\n        throw new URISyntaxException(\n            uri.toString(), ErrorMessages.create(\"invalidRelativePathInPackageUri\"));\n      }\n    }\n    var versionIdx = path.lastIndexOf('@');\n    if (versionIdx == -1) {\n      throw new URISyntaxException(\n          uri.toString(), ErrorMessages.create(\"missingVersionInPackageUri\", path));\n    }\n    this.uri = IoUtils.stripFragment(uri);\n    this.pathWithoutVersion = path.substring(0, versionIdx);\n    var checksumIdx = path.indexOf(\"::\");\n    var versionPart = path.substring(versionIdx + 1);","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/packages/PackageUri.java#L43-L79","documentation":"Validation in the PackageUri(URI) constructor: the URI is opaque (no '/' after the scheme, e.g. `package:foo`), but package URIs must be hierarchical so the path can carry name/version/checksum parts. Input at fault: an opaque URI passed where a hierarchical `package://...` URI is required.","triggerScenarios":"new PackageUri(uri) with a pathless URI such as 'package://example.com' or 'package://example.com/' (getPath() null or empty).","commonSituations":"Copying only the registry base URL as a dependency; programmatically building a URI and forgetting to append the package name/version path; string concatenation bugs that drop the path segment.","solutions":["Use the hierarchical form `package://<authority>/<path>` including the module path.","Obtain package URIs from the resolver or a valid package descriptor rather than constructing them by hand."],"exampleFix":"// before\nvar uri = URI.create(\"package://example.com\");\nvar pkg = new PackageUri(uri);\n// after\nvar uri = URI.create(\"package://example.com/my-pkg@1.2.3\");\nvar pkg = new PackageUri(uri);","handlingStrategy":"validation","validationCode":"boolean hasPath(URI uri) {\n  var p = uri.getPath();\n  return p != null && !p.isEmpty();\n}","typeGuard":"static boolean hasPackagePath(URI uri) {\n  return uri.getPath() != null && !uri.getPath().isEmpty();\n}","tryCatchPattern":"try {\n  var pkg = new PackageUri(uri);\n} catch (URISyntaxException e) {\n  throw new IllegalArgumentException(\"Package URI missing path: \" + uri, e);\n}","preventionTips":["Always append '/<package-name>@<version>' after the authority","Don't use a bare registry base URL as a dependency URI","Check path-preserving string concatenation when building URIs programmatically"],"tags":["pkl","package-uri","uri-validation","path"],"backgroundTag":"invalid-url-format","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}