{"record":{"id":"4f7b1b9da836ad10","repo":"apache/pulsar","slug":"size-of-data-received-by-longschema-is-not-8","errorCode":null,"errorMessage":"Size of data received by LongSchema is not 8","messagePattern":"Size of data received by LongSchema is not 8","errorType":"exception","errorClass":"SchemaSerializationException","httpStatus":null,"severity":"error","filePath":"pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/LongSchema.java","lineNumber":49,"sourceCode":"    private static final LongSchema INSTANCE;\n    private static final SchemaInfo SCHEMA_INFO;\n\n    static {\n        SCHEMA_INFO = SchemaInfoImpl.builder()\n            .name(\"INT64\")\n            .type(SchemaType.INT64)\n            .schema(new byte[0]).build();\n        INSTANCE = new LongSchema();\n    }\n\n    public static LongSchema of() {\n        return INSTANCE;\n    }\n\n    @Override\n    public void validate(byte[] message) {\n        if (message.length != 8) {\n            throw new SchemaSerializationException(\"Size of data received by LongSchema is not 8\");\n        }\n    }\n\n    @Override\n    public void validate(ByteBuf message) {\n        if (message.readableBytes() != 8) {\n            throw new SchemaSerializationException(\"Size of data received by LongSchema is not 8\");\n        }\n    }\n\n    @Override\n    public byte[] encode(Long data) {\n        if (null == data) {\n            return null;\n        } else {\n            return new byte[] {\n                (byte) (data >>> 56),\n                (byte) (data >>> 48),","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/LongSchema.java#L31-L67","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the producer and consumer use the same schema type (Schema.INT64) for the topic","Check the actual payload length before decoding; inspect topic schema via pulsar-admin schemas get","Fix truncation/corruption at the producing side; ensure bytes are not re-encoded or split in transit","Catch SchemaSerializationException and route the message to a dead-letter or recovery path"],"exampleFix":"// before\nLong value = Schema.INT64.decode(rawBytes);\n// after\nif (rawBytes.length != 8) {\n    throw new IllegalArgumentException(\"expected 8 bytes, got \" + rawBytes.length);\n}\nLong value = Schema.INT64.decode(rawBytes);","handlingStrategy":"validation","validationCode":"if (bytes == null || bytes.length != 8) { throw new IllegalArgumentException(\"LongSchema payload must be 8 bytes\"); }","typeGuard":"boolean isLongPayload(byte[] b) { return b != null && b.length == 8; }","tryCatchPattern":"try { Long v = Schema.INT64.decode(bytes); } catch (SchemaSerializationException e) { log.error(\"bad payload size\", e); /* dead-letter */ }","preventionTips":["Declare Schema.INT64 on both producer and consumer","Check topic schema with pulsar-admin schemas get before wiring a consumer","Guard payload length before decoding raw bytes"],"tags":["schema","serialization","pulsar-client"],"backgroundTag":"schema-validation-failed","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}