apache/pulsar · error · RuntimeException

GenericSchema interface implementation class must rewrite th

Error message

GenericSchema interface implementation class must rewrite this method !

What it means

GenericSchema.of(SchemaInfo) is a static interface method that intentionally throws RuntimeException: interfaces cannot supply a meaningful construction, so concrete GenericSchema implementations must provide the factory. Invoking GenericSchema.of(...) statically on the interface type always fails; you must call it on or through a concrete implementation such as the AutoConsumeSchema/AvroSchemaImpl-backed generic schemas obtained from the client implementation.

Source

Thrown at pulsar-client-api/src/main/java/org/apache/pulsar/client/api/schema/GenericSchema.java:50

public interface GenericSchema<T extends GenericRecord> extends Schema<T> {

    /**
     * Returns the list of fields.
     *
     * @return the list of fields of generic record.
     */
    List<Field> getFields();

    /**
     * Create a builder to build {@link GenericRecord}.
     *
     * @return generic record builder
     */
    GenericRecordBuilder newRecordBuilder();


    static GenericSchema<?> of(SchemaInfo schemaInfo) {
        throw new RuntimeException("GenericSchema interface implementation class must rewrite this method !");
    }

    static GenericSchema<?> of(SchemaInfo schemaInfo,
                            boolean useProvidedSchemaAsReaderSchema) {
        throw new RuntimeException("GenericSchema interface implementation class must rewrite this method !");
    }



}

View on GitHub (pinned to 820761864e)

Solutions

  1. Build the generic schema from the client implementation instead, e.g. via Schema.generic(schemaInfo) or the internal generic schema constructors (AvroSchemaImpl / GenericSchemaImpl).
  2. Use AutoConsumeSchema or Schema.AUTO_CONSUME() when you just need to read records without a specific schema class.
  3. If you implement GenericSchema yourself, expose a static of(SchemaInfo) on your concrete class and route callers there.

Example fix

// before
GenericSchema<?> schema = GenericSchema.of(schemaInfo); // always throws
// after
Schema<GenericRecord> schema = Schema.generic(schemaInfo);
Defensive patterns

Strategy: fallback

Validate before calling

// Never call the interface static directly; use the public factory
Schema<GenericRecord> schema = Schema.generic(schemaInfo);

Try / catch

GenericSchema<?> schema;
try {
    schema = GenericSchema.of(schemaInfo);
} catch (RuntimeException e) {
    schema = (GenericSchema<?>) Schema.generic(schemaInfo); // concrete implementation
}

Prevention

When it happens

Trigger: Calling GenericSchema.of(schemaInfo) or GenericSchema.of(schemaInfo, useProvidedSchemaAsReaderSchema) directly — the interface's static body always throws, regardless of arguments.

Common situations: IDE auto-import resolving the static of() to the interface instead of a concrete class; generic utility code written against the Schema API assuming a static factory exists on GenericSchema; following outdated examples that predate the concrete factory relocation.

Related errors


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