apache/pulsar · error · RuntimeException
Schema `${type}` is not supported to be used as a field for
Error message
Schema `${type}` is not supported to be used as a field for now What it means
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.
Source
Thrown at pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/FieldSchemaBuilderImpl.java:159
case TIMESTAMP:
baseSchema = LogicalTypes.timestampMillis().addToSchema(Schema.create(Schema.Type.LONG));
break;
case JSON:
checkArgument(genericSchema.getSchemaInfo().getType() == SchemaType.JSON,
"The field is expected to be using JSON schema but "
+ genericSchema.getSchemaInfo().getType() + " schema is found");
AvroBaseStructSchema genericJsonSchema = (AvroBaseStructSchema) genericSchema;
baseSchema = genericJsonSchema.getAvroSchema();
break;
case AVRO:
checkArgument(genericSchema.getSchemaInfo().getType() == SchemaType.AVRO,
"The field is expected to be using AVRO schema but "
+ genericSchema.getSchemaInfo().getType() + " schema is found");
GenericAvroSchema genericAvroSchema = (GenericAvroSchema) genericSchema;
baseSchema = genericAvroSchema.getAvroSchema();
break;
default:
throw new RuntimeException("Schema `" + type + "` is not supported to be used as a field for now");
}
for (Map.Entry<String, String> entry : properties.entrySet()) {
baseSchema.addProp(entry.getKey(), entry.getValue());
}
if (null != aliases) {
for (String alias : aliases) {
baseSchema.addAlias(alias);
}
}
final Schema finalSchema;
if (optional) {
if (defaultVal != null) {
finalSchema = SchemaBuilder.builder().unionOf()
.type(baseSchema)
.and()View on GitHub (pinned to 820761864e)
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
Example fix
// before
Schema schema = SchemaBuilder.aRecord().addField("f", FieldSchemaBuilder.of(SchemaType.NONE)).build();
// after
Schema schema = SchemaBuilder.aRecord().addField("f", FieldSchemaBuilder.of(SchemaType.STRING)).build(); Defensive patterns
Strategy: validation
Validate before calling
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); }
if (!isSupportedFieldType(type)) throw new IllegalArgumentException("Unsupported field schema type: " + type); Type guard
boolean isStructOrPrimitive(SchemaType t) { return SchemaType.isStructType(t) || t.isPrimitive(); } Try / catch
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; } Prevention
- 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
When it happens
Trigger: 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().
Common situations: 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.
Related errors
- Error during schema compatibility check with strategy ${stra
- Retrieve schema instance from schema info for type '${schema
- The input schema is not of type 'org.apache.avro.Schema'.
- Currently only AVRO and JSON record schema is supported
- Avro Record Builder doesn't support non-avro record as a fie
AI-assisted analysis of apache/pulsar@820761864e (2026-09-06).
Data as JSON: /api/errors/757f8574466c5265.
Report an issue: GitHub.