{"record":{"id":"70f1d36547547584","repo":"apache/pulsar","slug":"currently-only-avro-and-json-record-schema-is-supp","errorCode":null,"errorMessage":"Currently only AVRO and JSON record schema is supported","messagePattern":"Currently only AVRO and JSON record schema is supported","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/RecordSchemaBuilderImpl.java","lineNumber":83,"sourceCode":"        FieldSchemaBuilderImpl field = new FieldSchemaBuilderImpl(fieldName, genericSchema);\n        fields.add(field);\n        return field;\n    }\n\n    @Override\n    public RecordSchemaBuilder doc(String doc) {\n        this.doc = doc;\n        return this;\n    }\n\n    @Override\n    public SchemaInfo build(SchemaType schemaType) {\n        switch (schemaType) {\n            case JSON:\n            case AVRO:\n                break;\n            default:\n                throw new RuntimeException(\"Currently only AVRO and JSON record schema is supported\");\n        }\n\n        String schemaNs = NAMESPACE;\n        String schemaName = DEFAULT_SCHEMA_NAME;\n        if (name != null) {\n            String[] split = splitName(name);\n            schemaNs = split[0];\n            schemaName = split[1];\n        }\n\n        org.apache.avro.Schema baseSchema = org.apache.avro.Schema.createRecord(\n            schemaName != null ? schemaName : DEFAULT_SCHEMA_NAME,\n            doc,\n            schemaNs,\n            false\n        );\n\n        List<org.apache.avro.Schema.Field> avroFields = new ArrayList<>();","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/RecordSchemaBuilderImpl.java#L65-L101","documentation":"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.","triggerScenarios":"recordSchemaBuilder.build(SchemaType.PROTOBUF) or any non-JSON/AVRO type; programmatically parameterizing schema type from config that allows other values.","commonSituations":"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.","solutions":["Call build with SchemaType.JSON or SchemaType.AVRO only","For protobuf schemas use Schema.PROTOBUF(...) / ProtobufSchemaBuilder instead of the record builder","Validate configured schema type before calling build and map unsupported types to an explicit error early"],"exampleFix":"// before\nSchemaInfo info = builder.build(SchemaType.PROTOBUF); // throws\n// after\nSchemaInfo info = builder.build(SchemaType.AVRO);","handlingStrategy":"validation","validationCode":"if (schemaType != SchemaType.JSON && schemaType != SchemaType.AVRO) { throw new IllegalArgumentException(\"record builder supports only JSON/AVRO\"); }","typeGuard":null,"tryCatchPattern":"try { info = builder.build(type); } catch (RuntimeException e) { // clamp type to AVRO or surface a config error }","preventionTips":["Whitelist JSON/AVRO in any config that feeds build(SchemaType)","Use ProtobufSchemaBuilder for protobuf record schemas","Centralize schema-type mapping to avoid unsupported combos"],"tags":["schema","record","unsupported-type"],"backgroundTag":"invalid-schema-argument","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}