{"record":{"id":"51c52eb795892e82","repo":"apple/pkl","slug":"invalidmoduleurimissingslash-51c52e","errorCode":"invalidModuleUriMissingSlash","errorMessage":"invalidModuleUriMissingSlash","messagePattern":"invalidModuleUriMissingSlash","errorType":"error_code","errorClass":"URISyntaxException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/packages/PackageUri.java","lineNumber":46,"sourceCode":"  private final Version version;\n  private final String pathWithoutVersion;\n  private @Nullable Checksums checksums;\n\n  public static PackageUri create(String baseUri) {\n    try {\n      return new PackageUri(baseUri);\n    } catch (URISyntaxException e) {\n      throw new IllegalArgumentException(e);\n    }\n  }\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","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/packages/PackageUri.java#L28-L64","documentation":"URISyntaxException thrown by the PackageUri constructor when the given URI is opaque — it lacks the hierarchical `/` separator after the scheme (e.g. `package:foo/bar` instead of `package:/foo/bar`). A package URI must be hierarchical with scheme `package` or `projectpackage`.","triggerScenarios":"Constructing `new PackageUri(String)` or `new PackageUri(URI)` with an opaque URI such as `package:my.pkg` (no slash after the colon), or a URI whose scheme is not `package`/`projectpackage` (separate invalidSchemeInPackageUri error).","commonSituations":"Hand-writing a package URI in a PklProject dependency without the leading slash; programmatic URI building that concatenates scheme and path without `:/`; copying a URN-style identifier into a package URI field.","solutions":["Insert the hierarchical separator: `package:/...` instead of `package:...`","Validate the URI string before constructing, e.g. check it starts with `package:/` or `projectpackage:/`","If the value comes from config, quote/copy the exact package URI published by the package author","Use URI.create and inspect uri.isOpaque() yourself for a friendlier pre-check"],"exampleFix":"// before\nnew PackageUri(\"package:example.com/my-pkg@1.0.0\");\n// after\nnew PackageUri(\"package:/example.com/my-pkg@1.0.0\");","handlingStrategy":"validation","validationCode":"// validate before constructing PackageUri\nstatic boolean isValidPackageUri(String s) {\n  return s.startsWith(\"package:/\") || s.startsWith(\"projectpackage:/\");\n}","typeGuard":"PackageUri tryParsePackageUri(String s) {\n  if (s == null || !s.matches(\"(package|projectpackage):/.*\")) return null;\n  try { return new PackageUri(s); } catch (URISyntaxException e) { return null; }\n}","tryCatchPattern":"try {\n  var packageUri = new PackageUri(uriString);\n} catch (URISyntaxException e) {\n  if (e.getReason().contains(\"missing slash\") || e.getReason().contains(\"opaque\")) {\n    uriString = uriString.replaceFirst(\"^(package|projectpackage):\", \"$1:/\");\n  }\n}","preventionTips":["Always write package URIs with the hierarchical slash: `package:/...`","Normalize URIs programmatically before constructing PackageUri","Copy published package URIs verbatim from package docs","Unit-test any code that builds package URIs from parts"],"tags":["uri","validation","package-loading"],"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"}