apache/pulsar · error · SchemaSerializationException

Size of data received by LongSchema is not 8

Error message

Size of data received by LongSchema is not 8

What it means

LongSchema.validate() checks that the raw payload is exactly 8 bytes (a Java long). It throws SchemaSerializationException when the byte array handed to decode/validate is not 8 bytes long, refusing to interpret malformed data as a long.

Source

Thrown at pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/LongSchema.java:49

    private static final LongSchema INSTANCE;
    private static final SchemaInfo SCHEMA_INFO;

    static {
        SCHEMA_INFO = SchemaInfoImpl.builder()
            .name("INT64")
            .type(SchemaType.INT64)
            .schema(new byte[0]).build();
        INSTANCE = new LongSchema();
    }

    public static LongSchema of() {
        return INSTANCE;
    }

    @Override
    public void validate(byte[] message) {
        if (message.length != 8) {
            throw new SchemaSerializationException("Size of data received by LongSchema is not 8");
        }
    }

    @Override
    public void validate(ByteBuf message) {
        if (message.readableBytes() != 8) {
            throw new SchemaSerializationException("Size of data received by LongSchema is not 8");
        }
    }

    @Override
    public byte[] encode(Long data) {
        if (null == data) {
            return null;
        } else {
            return new byte[] {
                (byte) (data >>> 56),
                (byte) (data >>> 48),

View on GitHub (pinned to 820761864e)

Solutions

  1. Verify the producer and consumer use the same schema type (Schema.INT64) for the topic
  2. Check the actual payload length before decoding; inspect topic schema via pulsar-admin schemas get
  3. Fix truncation/corruption at the producing side; ensure bytes are not re-encoded or split in transit
  4. Catch SchemaSerializationException and route the message to a dead-letter or recovery path

Example fix

// before
Long value = Schema.INT64.decode(rawBytes);
// after
if (rawBytes.length != 8) {
    throw new IllegalArgumentException("expected 8 bytes, got " + rawBytes.length);
}
Long value = Schema.INT64.decode(rawBytes);
Defensive patterns

Strategy: validation

Validate before calling

if (bytes == null || bytes.length != 8) { throw new IllegalArgumentException("LongSchema payload must be 8 bytes"); }

Type guard

boolean isLongPayload(byte[] b) { return b != null && b.length == 8; }

Try / catch

try { Long v = Schema.INT64.decode(bytes); } catch (SchemaSerializationException e) { log.error("bad payload size", e); /* dead-letter */ }

Prevention

When it happens

Trigger: Calling schema.decode() on a byte[] or ByteBuf whose length/readableBytes is not 8 — e.g. decoding a payload produced by a different schema (IntSchema, String, Avro), a truncated message, or a topic whose schema changed.

Common situations: Producer and consumer disagree on schema for the same topic (consumer built with LongSchema but producer used IntegerSchema or JSON/Avro); manually wiring decode() on raw bytes from a compacted/bridged topic; data written by a non-Pulsar tool into the topic.

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 apache/pulsar@820761864e (2026-09-06). Data as JSON: /api/errors/4f7b1b9da836ad10. Report an issue: GitHub.