apache/pulsar · error · InvalidSchemaDataException
Invalid schema definition data for primitive schemas :length
Error message
Invalid schema definition data for primitive schemas :length of schema data should be zero, but ${dataLength} bytes is found What it means
PrimitiveSchemaDataValidator.validate enforces that schema definition bytes for primitive schema types (INT8..INT64, FLOAT, DOUBLE, DATE, TIME, TIMESTAMP, BOOLEAN, etc.) are empty, because primitives carry no schema definition — only the type. A non-empty payload means a malformed or mislabeled SchemaInfo. The error text embeds the offending byte length.
Source
Thrown at pulsar-broker/src/main/java/org/apache/pulsar/broker/service/schema/validator/PrimitiveSchemaDataValidator.java:41
/**
* Validate if the primitive schema is in expected form.
*/
class PrimitiveSchemaDataValidator implements SchemaDataValidator {
public static PrimitiveSchemaDataValidator of() {
return INSTANCE;
}
private static final PrimitiveSchemaDataValidator INSTANCE = new PrimitiveSchemaDataValidator();
private PrimitiveSchemaDataValidator() {}
@Override
public void validate(SchemaData schemaData) throws InvalidSchemaDataException {
byte[] data = schemaData.getData();
if (null != data && data.length > 0) {
throw new InvalidSchemaDataException("Invalid schema definition data for primitive schemas :"
+ "length of schema data should be zero, but " + data.length + " bytes is found");
}
}
}
View on GitHub (pinned to 820761864e)
Solutions
- Set the schema definition to an empty array when the type is primitive: new SchemaInfoImpl() with data = new byte[0] (or SchemaInfo.builder().data(new byte[0])).
- If you have a real definition payload, the schema is not primitive — register it as AVRO/JSON/PROTOBUF_NATIVE instead.
- Check the producing framework so it does not attach descriptor bytes to primitive schemas.
Example fix
// before
SchemaInfo info = SchemaInfoImpl.builder().type(SchemaType.INT32)
.data("int32".getBytes(UTF_8)).build(); // non-empty data
// after
SchemaInfo info = SchemaInfoImpl.builder().type(SchemaType.INT32)
.data(new byte[0]).build(); Defensive patterns
Strategy: validation
Validate before calling
import org.apache.pulsar.common.schema.SchemaType;
boolean isPrimitive(SchemaType t) {
return switch (t) {
case INT8, INT16, INT32, INT64, FLOAT, DOUBLE, BOOLEAN, DATE, TIME, TIMESTAMP -> true;
default -> false;
};
}
if (isPrimitive(info.getType()) && info.getData() != null && info.getData().length > 0) {
throw new IllegalArgumentException("Primitive schema " + info.getType() + " must have empty data");
} Type guard
boolean validPrimitiveSchemaData(SchemaInfo info) {
byte[] d = info.getData();
return d == null || d.length == 0;
} Prevention
- Prefer the built-in factories (Schema.INT32, Schema.BOOLEAN, ...) over hand-built SchemaInfo for primitives.
- Never copy the data field from a structured schema into a primitive SchemaInfo.
- Add a unit test asserting data length is 0 for all primitive schema infos your tooling emits.
When it happens
Trigger: Registering a schema whose type is a primitive but whose SchemaInfo.data (schema definition) is non-empty — e.g. hand-building SchemaInfo with type=INT32 plus leftover descriptor bytes, or a framework that always fills the definition field, hitting SchemaDataValidator.validateSchemaData on upload.
Common situations: Custom admin tooling copying a JSON/Avro SchemaInfo and only swapping the type field to a primitive; generated clients that set data to a placeholder like "{}"; tests constructing primitive SchemaInfo with dummy bytes.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- deserialize ProtobufNative Schema failed
- protobuf root message descriptor is null, please recheck roo
- Schema ${schemaType} is a client-side schema type
- Unknown schema type :
- Invalid schema definition data for string schema : '
AI-assisted analysis of apache/pulsar@820761864e (2026-09-06).
Data as JSON: /api/errors/b33eae8f4baaa281.
Report an issue: GitHub.