apple/pkl · error · DecodeException

Unexpected empty object array value

Error message

Unexpected empty object array value

What it means

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.

Solutions

  1. Regenerate the payload with a correct Pkl binary writer so non-primitives include their code slot
  2. Validate fixtures: every non-primitive array must have len >= 1 with a PklBinaryCode as element 0
  3. Check for corruption/truncation in stored binary data
  4. If writing a custom encoder, always emit the code slot before members

Example fix

// before
packer.packArrayHeader(0); // empty non-primitive
// after
packer.packArrayHeader(1 + members.length);
packer.packInt(PklBinaryCode.OBJECT.toInt());
Defensive patterns

Strategy: validation

Validate before calling

// Producer side: non-primitive arrays must include at least the code slot
if (members.length == 0 && requiresCodeSlot) {
  throw new IllegalStateException("non-primitive must declare a PklBinaryCode");
}

Try / catch

try {
  Object v = decoder.decode(bytes);
} catch (DecodeException e) {
  if ("Unexpected empty object array value".equals(e.getMessage())) {
    // payload malformed at source; regenerate it
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: Bugs in custom writers of Pkl binary data; truncated/corrupted cache files; test fixtures built by hand with wrong lengths.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08). Data as JSON: /api/errors/64b62ff6220952b0. Report an issue: GitHub.

Appendix: source

Thrown at pkl-core/src/main/java/org/pkl/core/util/pklbinary/AbstractPklBinaryDecoder.java:159

        yield doDecodeNull();
      }
      case STRING -> unpacker.unpackString();
      case INTEGER -> unpacker.unpackLong();
      case BOOLEAN -> unpacker.unpackBoolean();
      case FLOAT -> unpacker.unpackDouble();
      // non-primitive
      case ARRAY -> decodeNonPrimitive();
      // things we should never see outside a non-primitive
      case BINARY -> throw new DecodeException("Unexpected msgpack bin value");
      case MAP -> throw new DecodeException("Unexpected msgpack map value");
      case EXTENSION -> throw new DecodeException("Unexpected msgpack ext value");
    };
  }

  private Object decodeNonPrimitive() throws IOException {
    var len = unpacker.unpackArrayHeader();
    if (len < 1) {
      throw new DecodeException("Unexpected empty object array value");
    }

    var codeInt = unpacker.unpackInt();
    var code = PklBinaryCode.fromInt(codeInt);
    if (code == null) {
      throw new DecodeException("Unrecognized code 0x%x", (byte) codeInt);
    }

    return switch (code) {
      case OBJECT -> decodeObject(len);
      case MAP -> decodeMap(len);
      case MAPPING -> decodeMapping(len);
      case LIST -> decodeList(len);
      case LISTING -> decodeListing(len);
      case SET -> decodeSet(len);
      case DURATION -> decodeDuration(len);
      case DATASIZE -> decodeDataSize(len);
      case PAIR -> decodePair(len);

View on GitHub (pinned to f3efcbfc9b)