{"record":{"id":"5138c801ced24bd3","repo":"apache/pulsar","slug":"com-google-protobuf-message-is-not-assignable-from","errorCode":null,"errorMessage":"com.google.protobuf.Message is not assignable from ${pojo.getName()}","messagePattern":"com\\.google\\.protobuf\\.Message is not assignable from (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/ProtobufNativeSchema.java","lineNumber":123,"sourceCode":"    }\n\n    public static <T extends Message> ProtobufNativeSchema<T> of(Class<T> pojo) {\n        return of(pojo, new HashMap<>());\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    public static <T> ProtobufNativeSchema ofGenericClass(Class<T> pojo, Map<String, String> properties) {\n        SchemaDefinition<T> schemaDefinition = SchemaDefinition.<T>builder().withPojo(pojo)\n                .withProperties(properties).build();\n        return ProtobufNativeSchema.of(schemaDefinition);\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    public static <T> ProtobufNativeSchema of(SchemaDefinition<T> schemaDefinition) {\n        Class<T> pojo = schemaDefinition.getPojo();\n\n        if (!Message.class.isAssignableFrom(pojo)) {\n            throw new IllegalArgumentException(Message.class.getName()\n                    + \" is not assignable from \" + pojo.getName());\n        }\n        Descriptors.Descriptor descriptor = createProtobufNativeSchema(schemaDefinition.getPojo());\n\n        SchemaInfo schemaInfo = SchemaInfoImpl.builder()\n                .schema(ProtobufNativeSchemaUtils.serialize(descriptor))\n                .type(SchemaType.PROTOBUF_NATIVE)\n                .name(\"\")\n                .properties(schemaDefinition.getProperties())\n                .build();\n        try {\n            return new ProtobufNativeSchema(schemaInfo,\n                    (Message) pojo.getMethod(\"getDefaultInstance\").invoke(null));\n        } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {\n            throw new IllegalArgumentException(e);\n        }\n    }\n","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/ProtobufNativeSchema.java#L105-L141","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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)"],"exampleFix":"// before\nSchemaDefinition<Object> def = SchemaDefinition.<Object>builder().withPojo(PlainPojo.class).build();\nProtobufNativeSchema.of(def); // throws\n// after\nSchemaDefinition<GeneratedMsg> def = SchemaDefinition.<GeneratedMsg>builder().withPojo(GeneratedMsg.class).build();\nProtobufNativeSchema.of(def);","handlingStrategy":"type-guard","validationCode":"if (!com.google.protobuf.Message.class.isAssignableFrom(pojo)) { throw new IllegalArgumentException(pojo + \" must implement Message\"); }","typeGuard":"boolean isProtobufMessage(Class<?> c) { return com.google.protobuf.Message.class.isAssignableFrom(c); }","tryCatchPattern":"try { ProtobufNativeSchema.of(def); } catch (IllegalArgumentException e) { /* fall back to AVRO/JSON schema or fix pojo */ }","preventionTips":["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"],"tags":["protobuf","schema","illegal-argument"],"backgroundTag":"invalid-schema-argument","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"}