apache/pulsar · error · RuntimeException

Currently only AVRO and JSON record schema is supported

Error message

Currently only AVRO and JSON record schema is supported

What it means

RecordSchemaBuilderImpl.build(SchemaType) only supports JSON and AVRO schema types when assembling a record-based schema. Any other SchemaType (e.g. PROTOBUF, KEY_VALUE, STRING) passed to build() throws a generic RuntimeException.

Source

Thrown at pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/RecordSchemaBuilderImpl.java:83

        FieldSchemaBuilderImpl field = new FieldSchemaBuilderImpl(fieldName, genericSchema);
        fields.add(field);
        return field;
    }

    @Override
    public RecordSchemaBuilder doc(String doc) {
        this.doc = doc;
        return this;
    }

    @Override
    public SchemaInfo build(SchemaType schemaType) {
        switch (schemaType) {
            case JSON:
            case AVRO:
                break;
            default:
                throw new RuntimeException("Currently only AVRO and JSON record schema is supported");
        }

        String schemaNs = NAMESPACE;
        String schemaName = DEFAULT_SCHEMA_NAME;
        if (name != null) {
            String[] split = splitName(name);
            schemaNs = split[0];
            schemaName = split[1];
        }

        org.apache.avro.Schema baseSchema = org.apache.avro.Schema.createRecord(
            schemaName != null ? schemaName : DEFAULT_SCHEMA_NAME,
            doc,
            schemaNs,
            false
        );

        List<org.apache.avro.Schema.Field> avroFields = new ArrayList<>();

View on GitHub (pinned to 820761864e)

Solutions

  1. Call build with SchemaType.JSON or SchemaType.AVRO only
  2. For protobuf schemas use Schema.PROTOBUF(...) / ProtobufSchemaBuilder instead of the record builder
  3. Validate configured schema type before calling build and map unsupported types to an explicit error early

Example fix

// before
SchemaInfo info = builder.build(SchemaType.PROTOBUF); // throws
// after
SchemaInfo info = builder.build(SchemaType.AVRO);
Defensive patterns

Strategy: validation

Validate before calling

if (schemaType != SchemaType.JSON && schemaType != SchemaType.AVRO) { throw new IllegalArgumentException("record builder supports only JSON/AVRO"); }

Try / catch

try { info = builder.build(type); } catch (RuntimeException e) { // clamp type to AVRO or surface a config error }

Prevention

When it happens

Trigger: recordSchemaBuilder.build(SchemaType.PROTOBUF) or any non-JSON/AVRO type; programmatically parameterizing schema type from config that allows other values.

Common situations: Config-driven schema creation where the configured type isn't validated; trying to build a protobuf record schema via the record builder instead of ProtobufSchemaBuilder.

Related errors


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