{"record":{"id":"dee4cbd46522653f","repo":"apple/pkl","slug":"could-not-read-annotation-invalid-object","errorCode":null,"errorMessage":"Could not read annotation. Invalid object: ","messagePattern":"Could not read annotation\\. Invalid object: ","errorType":"exception","errorClass":"PklException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/packages/DependencyMetadata.java","lineNumber":175,"sourceCode":"                var checksums = obj.get(\"checksums\", DependencyMetadata::parseChecksums);\n                var packageUri = obj.get(\"uri\", PackageUtils::parsePackageUriWithoutChecksums);\n                return new RemoteDependency(packageUri, checksums);\n              });\n      ret.put(key, remoteDependency);\n    }\n    return ret;\n  }\n\n  private static List<PObject> parseAnnotations(Object ann)\n      throws JsonParseException, URISyntaxException {\n    if (!(ann instanceof JsArray arr)) {\n      throw new FormatException(\"array\", ann.getClass());\n    }\n    var annotations = new ArrayList<PObject>(arr.size());\n    for (var annotation : arr) {\n      var obj = parsePObject(annotation);\n      if (!(obj instanceof PObject pObject)) {\n        throw new PklException(\"Could not read annotation. Invalid object: \" + obj);\n      }\n      annotations.add(pObject);\n    }\n    return annotations;\n  }\n\n  private static Object parsePObject(@Nullable Object obj)\n      throws JsonParseException, URISyntaxException {\n    if (obj == null) {\n      return PNull.getInstance();\n    } else if (obj instanceof String string) {\n      return string;\n    } else if (obj instanceof Boolean bool) {\n      return bool;\n    } else if (obj instanceof Integer integer) {\n      return integer.longValue();\n    } else if (obj instanceof Long aLong) {\n      return aLong;","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/packages/DependencyMetadata.java#L157-L193","documentation":"PklException(\"Could not read annotation. Invalid object: \" + obj) is thrown by DependencyMetadata.parseAnnotations when an element inside the annotations array parses to something that is not a PObject (annotation objects must be JSON objects). The message includes the parsed value for diagnosis. It signals a structurally invalid annotation entry in package metadata.","triggerScenarios":"An element of the metadata `annotations` array is a string, number, or other non-object value, so parsePObject returns a non-PObject result.","commonSituations":"Hand-edited metadata with scalar annotation entries; custom publishing scripts serializing annotations as strings; corrupted or partially written metadata artifacts.","solutions":["Make every element of the `annotations` array a JSON object.","Regenerate the package metadata with `pkl project package`.","Inspect the value printed in the message to find which entry is malformed.","Re-publish/re-download the package if the artifact itself is bad."],"exampleFix":"// before\n{\"annotations\": [\"mit-license\"]}\n// after\n{\"annotations\": [{\"name\": \"license\", \"value\": \"MIT\"}]}","handlingStrategy":"validation","validationCode":"var anns = root.get(\"annotations\");\nfor (var a : anns) {\n  if (!a.isObject()) throw new IllegalStateException(\"annotation entries must be objects, got: \" + a);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure each annotations array element is a JSON object with expected name/value fields.","Avoid serializing annotations as plain strings in custom tools.","Regenerate metadata with official tooling after edits.","Re-parse published metadata as a post-publish smoke test."],"tags":["json","package-metadata","annotations","pkl"],"backgroundTag":"unexpected-api-response-shape","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"}