apache/pulsar · error · RuntimeException
Invalid Java object for schema type + type + : + val.getCl
Error message
Invalid Java object for schema type + type + : + val.getClass() + for field : " + name + "
What it means
SchemaUtils.validateFieldSchema checks that the Java value supplied for a field matches the expected Java classes for the field's SchemaType. When no class list is registered for that schema type at all, it throws RuntimeException 'Invalid Java object for schema type ... for field ...', meaning the type cannot accept any Java object in this validation path.
Source
Thrown at pulsar-common/src/main/java/org/apache/pulsar/client/impl/schema/SchemaUtils.java:126
SCHEMA_TYPE_CLASSES.put(
SchemaType.BYTES,
Arrays.asList(byte[].class, ByteBuffer.class, ByteBuf.class));
// build the reverse mapping
SCHEMA_TYPE_CLASSES
.forEach((type, classes) -> classes.forEach(clz -> JAVA_CLASS_SCHEMA_TYPES.put(clz, type)));
}
public static void validateFieldSchema(String name,
SchemaType type,
Object val) {
if (null == val) {
return;
}
List<Class<?>> expectedClasses = SCHEMA_TYPE_CLASSES.get(type);
if (null == expectedClasses) {
throw new RuntimeException("Invalid Java object for schema type " + type
+ " : " + val.getClass()
+ " for field : \"" + name + "\"");
}
boolean foundMatch = false;
for (Class<?> expectedCls : expectedClasses) {
if (expectedCls.isInstance(val)) {
foundMatch = true;
break;
}
}
if (!foundMatch) {
throw new RuntimeException("Invalid Java object for schema type " + type
+ " : " + val.getClass()
+ " for field : \"" + name + "\"");
}
View on GitHub (pinned to 820761864e)
Solutions
- Use a concrete supported SchemaType (INT8..STRING, BOOLEAN, BYTES, DATE, TIME, TIMESTAMP, etc.) for the field.
- Remove manual calls to validateFieldSchema for special types (AUTO/AUTO_CONSUME/AUTO_PUBLISH/KEY_VALUE) that are not meant to validate plain Java objects.
- Wrap validation in try/catch for RuntimeException to surface which field/type combination is unsupported, then correct the schema definition.
Example fix
// before
SchemaUtils.validateFieldSchema("f", val, SchemaType.AUTO_CONSUME, false);
// after
SchemaUtils.validateFieldSchema("f", val, SchemaType.INT32, false); // concrete type with registered classes Defensive patterns
Strategy: try-catch
Validate before calling
if (val != null && Set.of(SchemaType.AUTO, SchemaType.AUTO_CONSUME, SchemaType.AUTO_PUBLISH,
SchemaType.KEY_VALUE, SchemaType.JSON, SchemaType.NONE).contains(type)) {
throw new IllegalArgumentException("schema type " + type + " cannot validate plain Java objects");
} Try / catch
try {
SchemaUtils.validateFieldSchema(name, val, type, required);
} catch (RuntimeException e) {
throw new SchemaException("field '" + name + "' uses unsupported schema type " + type, e);
} Prevention
- Use concrete SchemaTypes with registered Java class mappings for field validation.
- Never run plain-object field validation for AUTO*/KEY_VALUE/JSON/NONE types.
- Catch RuntimeException and surface the field name for faster diagnosis.
When it happens
Trigger: Calling schema validation (e.g. Avro-based record schema building with SchemaUtils.validateFieldSchema) with a SchemaType that has no entry in SCHEMA_TYPE_CLASSES (such as special/auto types or unsupported types) while passing a non-null value.
Common situations: Using AUTO_, KEY_VALUE, JSON, or similar schema types in a manual field-validation flow; building schemas programmatically from POJOs where field type annotation maps to an unsupported SchemaType enum.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Avro Record Builder doesn't support non-avro record as a fie
- Invalid schema type: ${valueSchema}
- Currently + type.name() + is not supported
- Can not enable for all producers but denies for replicators,
- Error during schema compatibility check with strategy ${stra
AI-assisted analysis of apache/pulsar@820761864e (2026-09-06).
Data as JSON: /api/errors/80a754ca70ebe5a6.
Report an issue: GitHub.