apache/pulsar · error · SchemaSerializationException
Size of data received by BooleanSchema is not 1
Error message
Size of data received by BooleanSchema is not 1
What it means
BooleanSchema encodes booleans as exactly one byte. validate() rejects any payload whose length differs from 1 with SchemaSerializationException, so decoding/validating a message of the wrong size fails fast instead of producing garbage values.
Source
Thrown at pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/BooleanSchema.java:49
private static final BooleanSchema INSTANCE;
private static final SchemaInfo SCHEMA_INFO;
static {
SCHEMA_INFO = SchemaInfoImpl.builder()
.name("Boolean")
.type(SchemaType.BOOLEAN)
.schema(new byte[0]).build();
INSTANCE = new BooleanSchema();
}
public static BooleanSchema of() {
return INSTANCE;
}
@Override
public void validate(byte[] message) {
if (message.length != 1) {
throw new SchemaSerializationException("Size of data received by BooleanSchema is not 1");
}
}
@Override
public byte[] encode(Boolean message) {
if (null == message) {
return null;
} else {
return new byte[]{(byte) (message ? 1 : 0)};
}
}
@Override
public Boolean decode(byte[] bytes) {
if (null == bytes) {
return null;
}
validate(bytes);View on GitHub (pinned to 820761864e)
Solutions
- Ensure producers use Schema.BOOLEAN so values are encoded as exactly 1 byte
- Check the payload length is 1 before calling validate/decode
- Verify the topic's schema matches what producers actually publish (use broker schema validation enforce).
Example fix
// before
booleanSchema.validate(payload); // throws if payload.length != 1
// after
if (payload != null && payload.length == 1) {
booleanSchema.validate(payload);
} Defensive patterns
Strategy: validation
Validate before calling
if (message == null || message.length != 1) {
throw new IllegalArgumentException("Boolean payload must be exactly 1 byte");
} Type guard
boolean isValidBooleanPayload(byte[] msg) {
return msg != null && msg.length == 1;
} Try / catch
try {
schema.validate(message);
} catch (SchemaSerializationException e) {
log.warn("Skipping malformed boolean payload of length {}", message == null ? -1 : message.length);
} Prevention
- Always publish boolean topics with Schema.BOOLEAN
- Enable broker schema validation enforcement so mismatched producers fail at publish time
- Sanitize payloads coming from external bridges before decoding
When it happens
Trigger: Passing a byte[] of length 0 or >1 into Schema.BOOLEAN().validate(...) or a corrupted/wrongly-encoded payload into the decode path of a BOOLEAN schema topic.
Common situations: Publishing to a boolean-schema topic with a mismatched schema (e.g. sending strings or multi-byte data); hand-crafted payloads in tests or bridges from other systems producing non-1-byte booleans.
Related errors
- Size of data received by ByteSchema is not 1
- Size of data received by DoubleSchema is not 8
- Can not enable for all producers but denies for replicators,
- This method is not supported
- Can't get accurate schema information for topic ${topicName}
AI-assisted analysis of apache/pulsar@820761864e (2026-09-06).
Data as JSON: /api/errors/d7f4e663713ee519.
Report an issue: GitHub.