{"record":{"id":"757f8574466c5265","repo":"apache/pulsar","slug":"schema-type-is-not-supported-to-be-used-as-a","errorCode":null,"errorMessage":"Schema `${type}` is not supported to be used as a field for now","messagePattern":"Schema `(.+?)` is not supported to be used as a field for now","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/FieldSchemaBuilderImpl.java","lineNumber":159,"sourceCode":"            case TIMESTAMP:\n                baseSchema = LogicalTypes.timestampMillis().addToSchema(Schema.create(Schema.Type.LONG));\n                break;\n            case JSON:\n                checkArgument(genericSchema.getSchemaInfo().getType() == SchemaType.JSON,\n                        \"The field is expected to be using JSON schema but \"\n                                + genericSchema.getSchemaInfo().getType() + \" schema is found\");\n                AvroBaseStructSchema genericJsonSchema = (AvroBaseStructSchema) genericSchema;\n                baseSchema = genericJsonSchema.getAvroSchema();\n                break;\n            case AVRO:\n                checkArgument(genericSchema.getSchemaInfo().getType() == SchemaType.AVRO,\n                        \"The field is expected to be using AVRO schema but \"\n                                + genericSchema.getSchemaInfo().getType() + \" schema is found\");\n                GenericAvroSchema genericAvroSchema = (GenericAvroSchema) genericSchema;\n                baseSchema = genericAvroSchema.getAvroSchema();\n                break;\n            default:\n                throw new RuntimeException(\"Schema `\" + type + \"` is not supported to be used as a field for now\");\n        }\n\n        for (Map.Entry<String, String> entry : properties.entrySet()) {\n            baseSchema.addProp(entry.getKey(), entry.getValue());\n        }\n\n        if (null != aliases) {\n            for (String alias : aliases) {\n                baseSchema.addAlias(alias);\n            }\n        }\n\n        final Schema finalSchema;\n        if (optional) {\n            if (defaultVal != null) {\n                finalSchema = SchemaBuilder.builder().unionOf()\n                    .type(baseSchema)\n                    .and()","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/FieldSchemaBuilderImpl.java#L141-L177","documentation":"FieldSchemaBuilderImpl builds a schema for a single field of a struct (AVRO-based) schema. When the builder's schema type is neither AVRO/JSON/PROTO types handled above the switch, nor BOOLEAN/INT8..DOUBLE/STRING/BYTES/DATE/TIME/TIMESTAMP/LOCAL_* primitives, nor a generic Avro schema, the default branch throws a RuntimeException because only these types can currently be used as a field schema.","triggerScenarios":"Calling SchemaBuilder.aRecord().addField(...) with a FieldSchemaBuilder whose type() was set to an unsupported SchemaType (e.g. NONE, KEY_VALUE, EXTERNAL, AUTO_CONSUME, AUTO_PUBLISH) and then invoking build().","commonSituations":"Dynamically building record schemas from user/config-supplied type names where an unknown or unsupported type string maps to a SchemaType that isn't field-compatible; copying schema types from a KeyValue schema into a field.","solutions":["Use one of the supported field schema types (primitives like STRING/INT32/DOUBLE, or AVRO/JSON/Protobuf struct types, or GenericAvroSchema)","If you need a nested record, build it via SchemaBuilder.<T>.newRecordSchema()/aRecord() with an AVRO-compatible type instead of an unsupported SchemaType","Check SchemaType.isStructType / supported primitive list before invoking addField to fail fast with a clearer message"],"exampleFix":"// before\nSchema schema = SchemaBuilder.aRecord().addField(\"f\", FieldSchemaBuilder.of(SchemaType.NONE)).build();\n// after\nSchema schema = SchemaBuilder.aRecord().addField(\"f\", FieldSchemaBuilder.of(SchemaType.STRING)).build();","handlingStrategy":"validation","validationCode":"static boolean isSupportedFieldType(SchemaType t) { return t == SchemaType.STRING || t == SchemaType.BOOLEAN || t == SchemaType.INT8 || t == SchemaType.INT16 || t == SchemaType.INT32 || t == SchemaType.INT64 || t == SchemaType.FLOAT || t == SchemaType.DOUBLE || t == SchemaType.BYTES || t == SchemaType.DATE || t == SchemaType.TIME || t == SchemaType.TIMESTAMP || SchemaType.isStructType(t); }\nif (!isSupportedFieldType(type)) throw new IllegalArgumentException(\"Unsupported field schema type: \" + type);","typeGuard":"boolean isStructOrPrimitive(SchemaType t) { return SchemaType.isStructType(t) || t.isPrimitive(); }","tryCatchPattern":"try { fieldBuilder.build(); } catch (RuntimeException e) { if (e.getMessage().contains(\"not supported to be used as a field\")) { /* fallback to supported type */ } else throw e; }","preventionTips":["Whitelist schema types before calling addField","Never feed user-supplied type names directly into FieldSchemaBuilder.type()","Prefer static Schema.AVRO(JsonPojo.class) records over manual schema construction"],"tags":["schema","avro","unsupported-type"],"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-14T05:17:10.506Z"}