{"record":{"id":"6dd6547a70d544a0","repo":"apache/pulsar","slug":"size-of-data-received-by-intschema-is-not-4","errorCode":null,"errorMessage":"Size of data received by IntSchema is not 4","messagePattern":"Size of data received by IntSchema is not 4","errorType":"exception","errorClass":"SchemaSerializationException","httpStatus":null,"severity":"error","filePath":"pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/IntSchema.java","lineNumber":49,"sourceCode":"    private static final IntSchema INSTANCE;\n    private static final SchemaInfo SCHEMA_INFO;\n\n    static {\n        SCHEMA_INFO = SchemaInfoImpl.builder()\n            .name(\"INT32\")\n            .type(SchemaType.INT32)\n            .schema(new byte[0]).build();\n        INSTANCE = new IntSchema();\n    }\n\n    public static IntSchema of() {\n        return INSTANCE;\n    }\n\n    @Override\n    public void validate(byte[] message) {\n        if (message.length != 4) {\n            throw new SchemaSerializationException(\"Size of data received by IntSchema is not 4\");\n        }\n    }\n\n    @Override\n    public void validate(ByteBuf message) {\n        if (message.readableBytes() != 4) {\n            throw new SchemaSerializationException(\"Size of data received by IntSchema is not 4\");\n        }\n    }\n\n    @Override\n    public byte[] encode(Integer message) {\n        if (null == message) {\n            return null;\n        } else {\n            return new byte[] {\n                (byte) (message >>> 24),\n                (byte) (message >>> 16),","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/IntSchema.java#L31-L67","documentation":"IntSchema.validate(byte[]) requires the payload to be exactly 4 bytes (a 32-bit int). Any other length cannot be decoded as an INT32, so a SchemaSerializationException is thrown from validate, reached via decode().","triggerScenarios":"Calling Schema.INT32.decode(byte[]) or consuming with INT32 schema a message whose payload byte[] length != 4 (e.g. 8-byte long, 1-byte byte, or text).","commonSituations":"Producer/consumer schema mismatch (producer used INT64/STRING); raw-byte consumers on an INT32 topic; messages written by a different client version or language binding with wrong width.","solutions":["Ensure the producer encodes with Schema.INT32 (4 bytes), not INT8/INT16/INT64/STRING","Confirm the topic's schema is INT32 via the admin schema API and align the consumer","Guard with message.length == 4 before decode when processing raw bytes"],"exampleFix":"// before\nint v = Schema.INT32.decode(data);\n// after\nif (data != null && data.length == 4) { int v = Schema.INT32.decode(data); } else { /* handle mismatch */ }","handlingStrategy":"validation","validationCode":"if (payload == null || payload.length != 4) throw new IllegalArgumentException(\"INT32 payload must be 4 bytes, got \" + (payload == null ? \"null\" : payload.length));","typeGuard":"boolean isIntPayload(byte[] b) { return b != null && b.length == 4; }","tryCatchPattern":"try { int v = Schema.INT32.decode(payload); } catch (SchemaSerializationException e) { if (e.getMessage().contains(\"not 4\")) { routeToDlq(msg); } else throw e; }","preventionTips":["Use Schema.INT32 (not INT64/BYTE/SHORT) on both sides","Compare producer and consumer getSchemaInfo() at startup","Never hand-write int encoding for schema-validated topics"],"tags":["schema","serialization","int32"],"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"}