{"record":{"id":"321c239ed7eadeae","repo":"apple/pkl","slug":"missingauthorityinpackageuri","errorCode":"missingAuthorityInPackageUri","errorMessage":"missingAuthorityInPackageUri","messagePattern":"missingAuthorityInPackageUri","errorType":"error_code","errorClass":"URISyntaxException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/packages/PackageUri.java","lineNumber":56,"sourceCode":"  }\n\n  public PackageUri(String baseUri) throws URISyntaxException {\n    this(new URI(baseUri));\n  }\n\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));","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/packages/PackageUri.java#L38-L74","documentation":"Thrown by the PackageUri constructor when the URI has an acceptable scheme but no authority component. A package URI must carry an authority (the registry/project host), e.g. 'package://example.com/...'; 'package:/path' or 'package:path' is invalid.","triggerScenarios":"new PackageUri(uri) or PackageUtils.parsePackageUriWithoutChecksums where uri.getAuthority() returns null or the empty string, e.g. 'package:///foo@1.0.0' or 'package:foo@1.0.0'.","commonSituations":"Omitting the registry host when writing dependency URIs by hand; building URIs with URI.create that collapse an empty authority ('//'); copying URIs from docs and dropping the domain part.","solutions":["Add the registry/project authority after the scheme: package://example.com/my-pkg@1.2.3","Check that you use the '//' delimiter so URI parsing yields a non-empty authority","Validate the package URI against the value published in the dependency's PklProject"],"exampleFix":"// before\nvar uri = URI.create(\"package:///my-pkg@1.2.3\");\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 hasAuthority(URI uri) {\n  return uri.getAuthority() != null && !uri.getAuthority().isEmpty();\n}","typeGuard":"static boolean hasPackageAuthority(URI uri) {\n  return \"package\".equals(uri.getScheme()) && uri.getAuthority() != null && !uri.getAuthority().isEmpty();\n}","tryCatchPattern":"try {\n  var pkg = new PackageUri(uri);\n} catch (URISyntaxException e) {\n  throw new IllegalArgumentException(\"Package URI missing authority: \" + uri, e);\n}","preventionTips":["Include the registry host in every package URI","Check for the '//' delimiter after the scheme","Compare against the URI published in the package's PklProject"],"tags":["pkl","package-uri","uri-validation","authority"],"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-14T16:17:12.679Z"}