apache/pulsar · error · UnsupportedOperationException
Generic schema is not supported on schema type <schemaInfo.g
Error message
Generic schema is not supported on schema type <schemaInfo.getType()>'
What it means
GenericSchemaImpl.of(SchemaInfo) only supports AVRO and JSON schema types when creating generic schemas. For any other SchemaType (e.g. Protobuf, KeyValue, primitive types) it throws UnsupportedOperationException because there is no generic record representation for them.
Source
Thrown at pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/generic/GenericSchemaImpl.java:88
}
/**
* warning :
* we suggest migrate GenericSchemaImpl.of() to <GenericSchema Implementor>.of() method
* (e.g. GenericJsonSchema 、GenericAvroSchema )
* @param schemaInfo {@link SchemaInfo}
* @param useProvidedSchemaAsReaderSchema {@link Boolean}
* @return generic schema implementation
*/
public static GenericSchemaImpl of(SchemaInfo schemaInfo,
boolean useProvidedSchemaAsReaderSchema) {
switch (schemaInfo.getType()) {
case AVRO:
return new GenericAvroSchema(schemaInfo, useProvidedSchemaAsReaderSchema);
case JSON:
return new GenericJsonSchema(schemaInfo, useProvidedSchemaAsReaderSchema);
default:
throw new UnsupportedOperationException("Generic schema is not supported on schema type "
+ schemaInfo.getType() + "'");
}
}
}
View on GitHub (pinned to 820761864e)
Solutions
- Check schemaInfo.getType() and handle only AVRO/JSON with generic schemas
- Use the type-specific API for other schema types (e.g. ProtobufNativeSchema-based decoding)
- Read such topics with AutoConsumeSchema or typed schemas instead
- Reject/branch on unsupported types before constructing the generic schema
Example fix
// before
GenericSchema<?> gs = GenericSchemaImpl.of(schemaInfo); // UnsupportedOperationException for PROTOBUF
// after
if (schemaInfo.getType() == SchemaType.AVRO || schemaInfo.getType() == SchemaType.JSON) {
GenericSchema<?> gs = GenericSchemaImpl.of(schemaInfo);
} else {
throw new IllegalArgumentException("Use typed schema for " + schemaInfo.getType());
} Defensive patterns
Strategy: validation
Validate before calling
if (schemaInfo.getType() != SchemaType.AVRO && schemaInfo.getType() != SchemaType.JSON) {
throw new IllegalArgumentException("Generic schema supports only AVRO/JSON, topic uses: " + schemaInfo.getType());
} Type guard
boolean supportsGenericSchema(SchemaInfo info) {
return info.getType() == SchemaType.AVRO || info.getType() == SchemaType.JSON;
} Try / catch
try {
GenericSchema<?> gs = GenericSchemaImpl.of(schemaInfo);
} catch (UnsupportedOperationException e) {
// fall back to AutoConsumeSchema or typed schema for this type
} Prevention
- Check the topic's SchemaType before using generic schema APIs
- Use AutoConsumeSchema for heterogeneous/unmapped schema types
- Handle PROTOBUF and other types with dedicated schema classes
- Document supported generic schema types in shared consumer factory code
When it happens
Trigger: Calling GenericSchemaImpl.of(schemaInfo) or of(schemaInfo, useProvidedSchemaAsReaderSchema) with a SchemaInfo whose type is not AVRO or JSON.
Common situations: Auto-creating generic schemas from any topic's SchemaInfo without checking its type; topics using PROTOBUF/AVRO_REFLECTION/KEY_VALUE schemas accessed via generic reader APIs; default schema type fallbacks hitting unsupported branches.
Related errors
- AutoConsumeSchema is not supported with schemaId
- This schema is not meant to be used for encoding
- AutoConsumeSchema is not intended to be used for encoding
- Schema typed [<schema.getClass().getName()>], simple-type:[<
- Can't get generic schema for topic <schemaInfoProvider.getTo
AI-assisted analysis of apache/pulsar@820761864e (2026-09-06).
Data as JSON: /api/errors/9ba70087d9ab7ed4.
Report an issue: GitHub.