apache/pulsar · error · SchemaSerializationException
Size of data received by IntSchema is not 4
Error message
Size of data received by IntSchema is not 4
What it means
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().
Source
Thrown at pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/IntSchema.java:49
private static final IntSchema INSTANCE;
private static final SchemaInfo SCHEMA_INFO;
static {
SCHEMA_INFO = SchemaInfoImpl.builder()
.name("INT32")
.type(SchemaType.INT32)
.schema(new byte[0]).build();
INSTANCE = new IntSchema();
}
public static IntSchema of() {
return INSTANCE;
}
@Override
public void validate(byte[] message) {
if (message.length != 4) {
throw new SchemaSerializationException("Size of data received by IntSchema is not 4");
}
}
@Override
public void validate(ByteBuf message) {
if (message.readableBytes() != 4) {
throw new SchemaSerializationException("Size of data received by IntSchema is not 4");
}
}
@Override
public byte[] encode(Integer message) {
if (null == message) {
return null;
} else {
return new byte[] {
(byte) (message >>> 24),
(byte) (message >>> 16),View on GitHub (pinned to 820761864e)
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
Example fix
// before
int v = Schema.INT32.decode(data);
// after
if (data != null && data.length == 4) { int v = Schema.INT32.decode(data); } else { /* handle mismatch */ } Defensive patterns
Strategy: validation
Validate before calling
if (payload == null || payload.length != 4) throw new IllegalArgumentException("INT32 payload must be 4 bytes, got " + (payload == null ? "null" : payload.length)); Type guard
boolean isIntPayload(byte[] b) { return b != null && b.length == 4; } Try / catch
try { int v = Schema.INT32.decode(payload); } catch (SchemaSerializationException e) { if (e.getMessage().contains("not 4")) { routeToDlq(msg); } else throw e; } Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- This method is not supported
- Not implemented for ${this.getClass}
- Unknown version ${BytesSchemaVersion.of(schemaVersion)}
- Can't get accurate schema information for topic ${topicName}
- Size of data received by BooleanSchema is not 1
AI-assisted analysis of apache/pulsar@820761864e (2026-09-06).
Data as JSON: /api/errors/6dd6547a70d544a0.
Report an issue: GitHub.