{"record":{"id":"1d38bfddb05ce4ab","repo":"apache/pulsar","slug":"size-of-data-received-by-byteschema-is-not-1","errorCode":null,"errorMessage":"Size of data received by ByteSchema is not 1","messagePattern":"Size of data received by ByteSchema is not 1","errorType":"exception","errorClass":"SchemaSerializationException","httpStatus":null,"severity":"error","filePath":"pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/ByteSchema.java","lineNumber":49,"sourceCode":"    private static final ByteSchema INSTANCE;\n    private static final SchemaInfo SCHEMA_INFO;\n\n    static {\n        SCHEMA_INFO = SchemaInfoImpl.builder()\n            .name(\"INT8\")\n            .type(SchemaType.INT8)\n            .schema(new byte[0]).build();\n        INSTANCE = new ByteSchema();\n    }\n\n    public static ByteSchema of() {\n        return INSTANCE;\n    }\n\n    @Override\n    public void validate(byte[] message) {\n        if (message.length != 1) {\n            throw new SchemaSerializationException(\"Size of data received by ByteSchema is not 1\");\n        }\n    }\n\n    @Override\n    public void validate(ByteBuf message) {\n        if (message.readableBytes() != 1) {\n            throw new SchemaSerializationException(\"Size of data received by ByteSchema is not 1\");\n        }\n    }\n\n    @Override\n    public byte[] encode(Byte message) {\n        if (null == message) {\n            return null;\n        } else {\n            return new byte[]{message};\n        }\n    }","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/ByteSchema.java#L31-L67","documentation":"ByteSchema stores a signed 8-bit value in exactly one byte. Its byte[]-based validate() throws SchemaSerializationException when the array length is not 1, preventing misaligned or corrupted payloads from being silently misdecoded.","triggerScenarios":"Calling Schema.INT8/ByteSchema.validate(byte[]) with an empty or multi-byte array — e.g. decoding a message produced with a different schema (INT32, string, Avro) into an INT8 topic.","commonSituations":"Schema mismatch between producer and consumer; manual deserialization of raw topic bytes; migration from another system emitting differently sized integers.","solutions":["Publish with Schema.INT8 on the producer side so payloads are 1 byte","Confirm the topic schema actually matches INT8 (inspect with pulsar-admin schemas get)","Validate payload.length == 1 before decoding manually"],"exampleFix":"// before\nbyte v = byteSchema.decode(payload); // throws if length != 1\n// after\nif (payload.length == 1) {\n    byte v = byteSchema.decode(payload);\n} else {\n    throw new IllegalArgumentException(\"Unexpected payload size: \" + payload.length);\n}","handlingStrategy":"validation","validationCode":"if (message == null || message.length != 1) {\n    throw new IllegalArgumentException(\"INT8 payload must be exactly 1 byte\");\n}","typeGuard":"boolean isValidBytePayload(byte[] msg) {\n    return msg != null && msg.length == 1;\n}","tryCatchPattern":"try {\n    schema.validate(message);\n} catch (SchemaSerializationException e) {\n    log.warn(\"Malformed INT8 payload, length={}\", message == null ? -1 : message.length);\n}","preventionTips":["Match producer schema (Schema.INT8) to topic schema","Verify topic schema with pulsar-admin schemas get","Don't hand-roll byte encoding for typed topics"],"tags":["pulsar","schema","int8","validation","serialization"],"backgroundTag":"schema-payload-size-mismatch","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"}