{"record":{"id":"64b62ff6220952b0","repo":"apple/pkl","slug":"unexpected-empty-object-array-value","errorCode":null,"errorMessage":"Unexpected empty object array value","messagePattern":"Unexpected empty object array value","errorType":"exception","errorClass":"DecodeException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/util/pklbinary/AbstractPklBinaryDecoder.java","lineNumber":159,"sourceCode":"        yield doDecodeNull();\n      }\n      case STRING -> unpacker.unpackString();\n      case INTEGER -> unpacker.unpackLong();\n      case BOOLEAN -> unpacker.unpackBoolean();\n      case FLOAT -> unpacker.unpackDouble();\n      // non-primitive\n      case ARRAY -> decodeNonPrimitive();\n      // things we should never see outside a non-primitive\n      case BINARY -> throw new DecodeException(\"Unexpected msgpack bin value\");\n      case MAP -> throw new DecodeException(\"Unexpected msgpack map value\");\n      case EXTENSION -> throw new DecodeException(\"Unexpected msgpack ext value\");\n    };\n  }\n\n  private Object decodeNonPrimitive() throws IOException {\n    var len = unpacker.unpackArrayHeader();\n    if (len < 1) {\n      throw new DecodeException(\"Unexpected empty object array value\");\n    }\n\n    var codeInt = unpacker.unpackInt();\n    var code = PklBinaryCode.fromInt(codeInt);\n    if (code == null) {\n      throw new DecodeException(\"Unrecognized code 0x%x\", (byte) codeInt);\n    }\n\n    return switch (code) {\n      case OBJECT -> decodeObject(len);\n      case MAP -> decodeMap(len);\n      case MAPPING -> decodeMapping(len);\n      case LIST -> decodeList(len);\n      case LISTING -> decodeListing(len);\n      case SET -> decodeSet(len);\n      case DURATION -> decodeDuration(len);\n      case DATASIZE -> decodeDataSize(len);\n      case PAIR -> decodePair(len);","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/util/pklbinary/AbstractPklBinaryDecoder.java#L141-L177","documentation":"DecodeException thrown by decodeNonPrimitive() when the msgpack array header length is less than 1, i.e. an empty array where a Pkl-typed non-primitive value was expected. Every non-primitive Pkl binary value must start with at least one slot holding its PklBinaryCode, so an empty array cannot be decoded.","triggerScenarios":"Producer encoded an empty array at a position where an object/map/list/etc. was required; corrupted payload whose array header says 0 elements; hand-assembled msgpack.","commonSituations":"Bugs in custom writers of Pkl binary data; truncated/corrupted cache files; test fixtures built by hand with wrong lengths.","solutions":["Regenerate the payload with a correct Pkl binary writer so non-primitives include their code slot","Validate fixtures: every non-primitive array must have len >= 1 with a PklBinaryCode as element 0","Check for corruption/truncation in stored binary data","If writing a custom encoder, always emit the code slot before members"],"exampleFix":"// before\npacker.packArrayHeader(0); // empty non-primitive\n// after\npacker.packArrayHeader(1 + members.length);\npacker.packInt(PklBinaryCode.OBJECT.toInt());","handlingStrategy":"validation","validationCode":"// Producer side: non-primitive arrays must include at least the code slot\nif (members.length == 0 && requiresCodeSlot) {\n  throw new IllegalStateException(\"non-primitive must declare a PklBinaryCode\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  Object v = decoder.decode(bytes);\n} catch (DecodeException e) {\n  if (\"Unexpected empty object array value\".equals(e.getMessage())) {\n    // payload malformed at source; regenerate it\n  } else throw e;\n}","preventionTips":["Always emit the PklBinaryCode as the first array element","Never encode empty arrays as Pkl non-primitives; use null or a typed empty structure","Round-trip test custom encoders","Checksum stored binary artifacts to detect corruption"],"tags":["msgpack","decoding","pkl-binary","malformed-input"],"backgroundTag":"schema-validation-failed","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}