{"record":{"id":"9ba70087d9ab7ed4","repo":"apache/pulsar","slug":"generic-schema-is-not-supported-on-schema-type-sc","errorCode":null,"errorMessage":"Generic schema is not supported on schema type <schemaInfo.getType()>'","messagePattern":"Generic schema is not supported on schema type <schemaInfo\\.getType\\(\\)>'","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/generic/GenericSchemaImpl.java","lineNumber":88,"sourceCode":"    }\n\n    /**\n     * warning :\n     * we suggest migrate GenericSchemaImpl.of() to  <GenericSchema Implementor>.of() method\n     * (e.g. GenericJsonSchema 、GenericAvroSchema )\n     * @param schemaInfo {@link SchemaInfo}\n     * @param useProvidedSchemaAsReaderSchema {@link Boolean}\n     * @return generic schema implementation\n     */\n    public static GenericSchemaImpl of(SchemaInfo schemaInfo,\n                                       boolean useProvidedSchemaAsReaderSchema) {\n        switch (schemaInfo.getType()) {\n            case AVRO:\n                return new GenericAvroSchema(schemaInfo, useProvidedSchemaAsReaderSchema);\n            case JSON:\n                return new GenericJsonSchema(schemaInfo, useProvidedSchemaAsReaderSchema);\n            default:\n                throw new UnsupportedOperationException(\"Generic schema is not supported on schema type \"\n                    + schemaInfo.getType() + \"'\");\n        }\n    }\n}\n","sourceCodeStart":70,"sourceCodeEnd":93,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/generic/GenericSchemaImpl.java#L70-L93","documentation":"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.","triggerScenarios":"Calling GenericSchemaImpl.of(schemaInfo) or of(schemaInfo, useProvidedSchemaAsReaderSchema) with a SchemaInfo whose type is not AVRO or JSON.","commonSituations":"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.","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"],"exampleFix":"// before\nGenericSchema<?> gs = GenericSchemaImpl.of(schemaInfo); // UnsupportedOperationException for PROTOBUF\n// after\nif (schemaInfo.getType() == SchemaType.AVRO || schemaInfo.getType() == SchemaType.JSON) {\n    GenericSchema<?> gs = GenericSchemaImpl.of(schemaInfo);\n} else {\n    throw new IllegalArgumentException(\"Use typed schema for \" + schemaInfo.getType());\n}","handlingStrategy":"validation","validationCode":"if (schemaInfo.getType() != SchemaType.AVRO && schemaInfo.getType() != SchemaType.JSON) {\n    throw new IllegalArgumentException(\"Generic schema supports only AVRO/JSON, topic uses: \" + schemaInfo.getType());\n}","typeGuard":"boolean supportsGenericSchema(SchemaInfo info) {\n    return info.getType() == SchemaType.AVRO || info.getType() == SchemaType.JSON;\n}","tryCatchPattern":"try {\n    GenericSchema<?> gs = GenericSchemaImpl.of(schemaInfo);\n} catch (UnsupportedOperationException e) {\n    // fall back to AutoConsumeSchema or typed schema for this type\n}","preventionTips":["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"],"tags":["pulsar","schema","generic-schema","unsupported-operation"],"backgroundTag":"unsupported-schema-type","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}