apache/pulsar · error · IllegalArgumentException
The input schema is not of type 'org.apache.avro.Schema'.
Error message
The input schema is not of type 'org.apache.avro.Schema'.
What it means
NativeAvroBytesSchema's constructor validates that the object passed in is an org.apache.avro.Schema instance. If it is anything else (a String, a POJO, a Class, etc.) it throws IllegalArgumentException immediately at schema construction.
Source
Thrown at pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/NativeAvroBytesSchema.java:64
this.nativeSchema = schema;
Map<String, String> properties = new HashMap<>();
properties.put(ALWAYS_ALLOW_NULL, "true");
properties.put(JSR310_CONVERSION_ENABLED, "false");
this.schemaInfo = SchemaInfo.builder()
.name("")
.schema(schema.toString().getBytes(StandardCharsets.UTF_8))
.properties(properties)
.type(SchemaType.AVRO)
.build();
}
public NativeAvroBytesSchema(Object schema) {
this(validateSchema(schema));
}
private static org.apache.avro.Schema validateSchema (Object schema) {
if (!(schema instanceof org.apache.avro.Schema)) {
throw new IllegalArgumentException("The input schema is not of type 'org.apache.avro.Schema'.");
}
return (org.apache.avro.Schema) schema;
}
@Override
public byte[] encode(byte[] message) {
return message;
}
/* decode should not be used because this is a Schema to be used on the Producer side */
@Override
public byte[] decode(byte[] bytes, byte[] schemaVersion) {
throw new UnsupportedOperationException();
}
@Override
public SchemaInfo getSchemaInfo() {
return schemaInfo;View on GitHub (pinned to 820761864e)
Solutions
- Parse the raw JSON into an Avro Schema first: new Schema.Parser().parse(schemaJson)
- Ensure the variable's compile-time type is org.apache.avro.Schema
- Use Schema.AVRO(SomePojo.class) if you want a POJO-driven schema instead of NativeAvroBytesSchema
Example fix
// before
NativeAvroBytesSchema s = new NativeAvroBytesSchema("{"type":"record"...}");
// after
org.apache.avro.Schema avro = new Schema.Parser().parse("{"type":"record"...}");
NativeAvroBytesSchema s = new NativeAvroBytesSchema(avro); Defensive patterns
Strategy: type-guard
Validate before calling
if (!(obj instanceof org.apache.avro.Schema)) { throw new IllegalArgumentException("must be an org.apache.avro.Schema"); } Type guard
boolean isAvroSchema(Object o) { return o instanceof org.apache.avro.Schema; } Try / catch
try { new NativeAvroBytesSchema<>(obj); } catch (IllegalArgumentException e) { /* parse schema from JSON and retry */ } Prevention
- Parse schema strings with new Schema.Parser().parse(...) before constructing
- Keep variables typed as org.apache.avro.Schema
- Prefer Schema.AVRO(Pojo.class) unless you specifically need native bytes passthrough
When it happens
Trigger: new NativeAvroBytesSchema(someString) or passing a Pulsar SchemaInfo/other schema object instead of a real org.apache.avro.Schema (e.g. Schema.Parser().parse(...) result).
Common situations: Mixing up Avro schema JSON text with a parsed Schema object; passing a SchemaDefinition or generic Object from generic API; refactors that changed the schema variable's type.
Related errors
- Error during schema compatibility check with strategy ${stra
- Retrieve schema instance from schema info for type '${schema
- Schema `${type}` is not supported to be used as a field for
- com.google.protobuf.Message is not assignable from ${pojo.ge
- com.google.protobuf.Message is not assignable from ${pojo.ge
AI-assisted analysis of apache/pulsar@820761864e (2026-09-06).
Data as JSON: /api/errors/f08bb7c7898b86d9.
Report an issue: GitHub.