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

  1. Check schemaInfo.getType() and handle only AVRO/JSON with generic schemas
  2. Use the type-specific API for other schema types (e.g. ProtobufNativeSchema-based decoding)
  3. Read such topics with AutoConsumeSchema or typed schemas instead
  4. 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

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


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