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

  1. 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])).
  2. If you have a real definition payload, the schema is not primitive — register it as AVRO/JSON/PROTOBUF_NATIVE instead.
  3. 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

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


AI-assisted analysis of apache/pulsar@820761864e (2026-09-06). Data as JSON: /api/errors/b33eae8f4baaa281. Report an issue: GitHub.