apache/pulsar · error · IllegalArgumentException
com.google.protobuf.Message is not assignable from ${pojo.ge
Error message
com.google.protobuf.Message is not assignable from ${pojo.getName()} What it means
ProtobufNativeSchema.of(SchemaDefinition) requires the schema's POJO to implement com.google.protobuf.Message. Otherwise it throws IllegalArgumentException stating Message is not assignable from the pojo's class name.
Source
Thrown at pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/ProtobufNativeSchema.java:123
}
public static <T extends Message> ProtobufNativeSchema<T> of(Class<T> pojo) {
return of(pojo, new HashMap<>());
}
@SuppressWarnings("unchecked")
public static <T> ProtobufNativeSchema ofGenericClass(Class<T> pojo, Map<String, String> properties) {
SchemaDefinition<T> schemaDefinition = SchemaDefinition.<T>builder().withPojo(pojo)
.withProperties(properties).build();
return ProtobufNativeSchema.of(schemaDefinition);
}
@SuppressWarnings("unchecked")
public static <T> ProtobufNativeSchema of(SchemaDefinition<T> schemaDefinition) {
Class<T> pojo = schemaDefinition.getPojo();
if (!Message.class.isAssignableFrom(pojo)) {
throw new IllegalArgumentException(Message.class.getName()
+ " is not assignable from " + pojo.getName());
}
Descriptors.Descriptor descriptor = createProtobufNativeSchema(schemaDefinition.getPojo());
SchemaInfo schemaInfo = SchemaInfoImpl.builder()
.schema(ProtobufNativeSchemaUtils.serialize(descriptor))
.type(SchemaType.PROTOBUF_NATIVE)
.name("")
.properties(schemaDefinition.getProperties())
.build();
try {
return new ProtobufNativeSchema(schemaInfo,
(Message) pojo.getMethod("getDefaultInstance").invoke(null));
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new IllegalArgumentException(e);
}
}
View on GitHub (pinned to 820761864e)
Solutions
- Generate the message class with protoc / protobuf-maven-plugin and pass that generated class to SchemaDefinition.of(...)
- Use Schema.AVRO(...)/JSONSchema for non-protobuf POJOs
- Verify the class actually implements com.google.protobuf.Message (check generated sources and protobuf dependency version)
Example fix
// before SchemaDefinition<Object> def = SchemaDefinition.<Object>builder().withPojo(PlainPojo.class).build(); ProtobufNativeSchema.of(def); // throws // after SchemaDefinition<GeneratedMsg> def = SchemaDefinition.<GeneratedMsg>builder().withPojo(GeneratedMsg.class).build(); ProtobufNativeSchema.of(def);
Defensive patterns
Strategy: type-guard
Validate before calling
if (!com.google.protobuf.Message.class.isAssignableFrom(pojo)) { throw new IllegalArgumentException(pojo + " must implement Message"); } Type guard
boolean isProtobufMessage(Class<?> c) { return com.google.protobuf.Message.class.isAssignableFrom(c); } Try / catch
try { ProtobufNativeSchema.of(def); } catch (IllegalArgumentException e) { /* fall back to AVRO/JSON schema or fix pojo */ } Prevention
- Ensure classes passed to SchemaDefinition.of are protoc-generated
- Run protobuf-maven-plugin/protoc in the build
- Check the instanceof-Msg contract before choosing ProtobufNativeSchema
When it happens
Trigger: Calling ProtobufNativeSchema.of(SchemaDefinition.of(SomePojo.class)) where SomePojo is not a generated protobuf message class (a plain Java bean, an Avro POJO, or a hand-written class).
Common situations: Using ProtobufNativeSchema with a non-protobuf class by mistake; confusing ProtobufSchema/ProtobufNativeSchema requirements; a proto file compiled without protoc so no Message subclass was generated.
Related errors
- com.google.protobuf.Message is not assignable from ${pojo.ge
- Retrieve schema instance from schema info for type '${schema
- The input schema is not of type 'org.apache.avro.Schema'.
- ${fileDescriptor.getFullName()} can't resolve dependency '${
- '${fileDescriptorProto.getName()}' can't resolve dependency
AI-assisted analysis of apache/pulsar@820761864e (2026-09-06).
Data as JSON: /api/errors/5138c801ced24bd3.
Report an issue: GitHub.