{"record":{"id":"b33eae8f4baaa281","repo":"apache/pulsar","slug":"invalid-schema-definition-data-for-primitive-schem","errorCode":null,"errorMessage":"Invalid schema definition data for primitive schemas :length of schema data should be zero, but ${dataLength} bytes is found","messagePattern":"Invalid schema definition data for primitive schemas :length of schema data should be zero, but (.+?) bytes is found","errorType":"validation","errorClass":"InvalidSchemaDataException","httpStatus":null,"severity":"error","filePath":"pulsar-broker/src/main/java/org/apache/pulsar/broker/service/schema/validator/PrimitiveSchemaDataValidator.java","lineNumber":41,"sourceCode":"\n/**\n * Validate if the primitive schema is in expected form.\n */\nclass PrimitiveSchemaDataValidator implements SchemaDataValidator {\n\n    public static PrimitiveSchemaDataValidator of() {\n        return INSTANCE;\n    }\n\n    private static final PrimitiveSchemaDataValidator INSTANCE = new PrimitiveSchemaDataValidator();\n\n    private PrimitiveSchemaDataValidator() {}\n\n    @Override\n    public void validate(SchemaData schemaData) throws InvalidSchemaDataException {\n        byte[] data = schemaData.getData();\n        if (null != data && data.length > 0) {\n            throw new InvalidSchemaDataException(\"Invalid schema definition data for primitive schemas :\"\n                + \"length of schema data should be zero, but \" + data.length + \" bytes is found\");\n        }\n    }\n}\n","sourceCodeStart":23,"sourceCodeEnd":46,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/schema/validator/PrimitiveSchemaDataValidator.java#L23-L46","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nSchemaInfo info = SchemaInfoImpl.builder().type(SchemaType.INT32)\n    .data(\"int32\".getBytes(UTF_8)).build(); // non-empty data\n// after\nSchemaInfo info = SchemaInfoImpl.builder().type(SchemaType.INT32)\n    .data(new byte[0]).build();","handlingStrategy":"validation","validationCode":"import org.apache.pulsar.common.schema.SchemaType;\nboolean isPrimitive(SchemaType t) {\n    return switch (t) {\n        case INT8, INT16, INT32, INT64, FLOAT, DOUBLE, BOOLEAN, DATE, TIME, TIMESTAMP -> true;\n        default -> false;\n    };\n}\nif (isPrimitive(info.getType()) && info.getData() != null && info.getData().length > 0) {\n    throw new IllegalArgumentException(\"Primitive schema \" + info.getType() + \" must have empty data\");\n}","typeGuard":"boolean validPrimitiveSchemaData(SchemaInfo info) {\n    byte[] d = info.getData();\n    return d == null || d.length == 0;\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["pulsar","schema-validation"],"backgroundTag":"schema-validation-failed","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"}