{"record":{"id":"bc8a72e0469ed91d","repo":"apache/pulsar","slug":"com-google-protobuf-message-is-not-assignable-from-bc8a72","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/ProtobufSchema.java","lineNumber":109,"sourceCode":"    }\n\n    public static <T extends Message> ProtobufSchema<T> of(Class<T> pojo) {\n        return of(pojo, new HashMap<>());\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    public static <T> ProtobufSchema ofGenericClass(Class<T> pojo, Map<String, String> properties) {\n        SchemaDefinition<T> schemaDefinition = SchemaDefinition.<T>builder().withPojo(pojo)\n                .withProperties(properties).build();\n        return ProtobufSchema.of(schemaDefinition);\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    public static <T> ProtobufSchema 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\n        // The application named this class, so let Avro reflect over it and over the protobuf runtime\n        // types avro-protobuf resolves alongside it. This has to happen before the schema is derived,\n        // not after: deriving it is itself a reflective resolution, which is also why there is no\n        // derived schema to expand from here. Encoding and decoding go through protobuf's own reader\n        // and writer, so the message's nested types are never resolved by Avro.\n        AvroTrustedClasses.trustExactly(pojo);\n\n            SchemaInfo schemaInfo = SchemaInfoImpl.builder()\n                    .schema(createProtobufAvroSchema(schemaDefinition.getPojo()).toString().getBytes(UTF_8))\n                    .type(SchemaType.PROTOBUF)\n                    .name(\"\")\n                    .properties(schemaDefinition.getProperties())\n                    .build();\n\n        try {","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/ProtobufSchema.java#L91-L127","documentation":"ProtobufSchema.of(SchemaDefinition) requires the POJO to be a com.google.protobuf.Message implementation; otherwise it throws IllegalArgumentException naming the offending class. It cannot derive a protobuf schema from an arbitrary class.","triggerScenarios":"ProtobufSchema.of(SchemaDefinition.of(PlainPojo.class)) where PlainPojo is not generated by protoc; passing an Avro or JSON POJO by mistake.","commonSituations":"Reusing a SchemaDefinition built for AVRO/JSON with ProtobufSchema; forgetting to run protoc/maven plugin so the Message class doesn't exist; classpath containing a stub with the same name.","solutions":["Pass a protoc-generated Message class: SchemaDefinition.<MyMsg>builder().withPojo(MyMsg.class).build()","Regenerate sources with the protobuf-maven-plugin if the Message class is missing","Use the appropriate schema type (AVRO/JSON) for non-protobuf POJOs"],"exampleFix":"// before\nProtobufSchema.of(SchemaDefinition.<Pojo>builder().withPojo(Pojo.class).build()); // Pojo not a Message\n// after\nProtobufSchema.of(SchemaDefinition.<MyProto.MyMsg>builder().withPojo(MyProto.MyMsg.class).build());","handlingStrategy":"type-guard","validationCode":"if (!com.google.protobuf.Message.class.isAssignableFrom(pojo)) { throw new IllegalArgumentException(\"ProtobufSchema requires a generated Message class\"); }","typeGuard":"boolean isProtobufMessage(Class<?> c) { return com.google.protobuf.Message.class.isAssignableFrom(c); }","tryCatchPattern":"try { ProtobufSchema.of(def); } catch (IllegalArgumentException e) { /* use correct schema type for this pojo */ }","preventionTips":["Only pass protoc-generated Message classes","Verify build generates protobuf sources before schema wiring","Choose AVRO/JSON schema types for plain POJOs"],"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-14T05:17:10.506Z"}