{"record":{"id":"7fe5fe0d55a06376","repo":"apple/pkl","slug":"missingversioninpackageuri","errorCode":"missingVersionInPackageUri","errorMessage":"missingVersionInPackageUri","messagePattern":"missingVersionInPackageUri","errorType":"error_code","errorClass":"URISyntaxException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/packages/PackageUri.java","lineNumber":73,"sourceCode":"    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);\n    if (checksumIdx > versionIdx) {\n      var checksumPart = path.substring(checksumIdx + 2);\n      versionPart = path.substring(versionIdx + 1, checksumIdx);\n      this.checksums = parseChecksumPart(checksumPart);\n    }\n    try {\n      this.version = Version.parse(versionPart);\n    } catch (IllegalArgumentException e) {\n      throw new URISyntaxException(uri.toString(), e.getMessage());\n    }\n  }\n","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/packages/PackageUri.java#L55-L91","documentation":"Validation in the PackageUri(URI) constructor: after the authority check, the URI's path is null or empty, meaning the package URI carries no path segment. Package URIs must include a path holding the package coordinates; the input at fault is a `package://authority` URI with nothing after the authority.","triggerScenarios":"new PackageUri(uri) or parsePackageUriWithoutChecksums with a path like '/my-pkg' lacking '@1.2.3'; versionIdx = path.lastIndexOf('@') returns -1.","commonSituations":"Referencing a package without pinning a version; stripping the '@version' while transforming URIs; older dependency declarations written before version pinning became required.","solutions":["Append the package path (name, version and optional checksum parts) after the authority.","Use a Package URI produced by the package manager instead of a hand-built URI."],"exampleFix":"// before\nvar uri = URI.create(\"package://example.com/my-pkg\");\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 hasVersion(String packageUriPath) {\n  return packageUriPath != null && packageUriPath.lastIndexOf('@') != -1;\n}","typeGuard":"static boolean isVersionedPackageUri(String uriStr) {\n  return uriStr != null && uriStr.lastIndexOf('@') != -1;\n}","tryCatchPattern":"try {\n  var pkg = new PackageUri(URI.create(uriStr));\n} catch (URISyntaxException e) {\n  throw new IllegalArgumentException(\"Package URI must include '@<version>': \" + uriStr, e);\n}","preventionTips":["Pin an explicit version in every dependency URI","Copy URIs verbatim from the registry or PklProject","Keep the '@version' suffix when transforming URI strings"],"tags":["pkl","package-uri","version","uri-validation"],"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"}