{"record":{"id":"9ae24adaec29e75a","repo":"apache/pulsar","slug":"deserialize-protobufnative-schema-failed","errorCode":null,"errorMessage":"deserialize ProtobufNative Schema failed","messagePattern":"deserialize ProtobufNative Schema failed","errorType":"validation","errorClass":"InvalidSchemaDataException","httpStatus":null,"severity":"error","filePath":"pulsar-broker/src/main/java/org/apache/pulsar/broker/service/schema/validator/ProtobufNativeSchemaDataValidator.java","lineNumber":34,"sourceCode":" * specific language governing permissions and limitations\n * under the License.\n */\npackage org.apache.pulsar.broker.service.schema.validator;\n\nimport com.google.protobuf.Descriptors;\nimport org.apache.pulsar.broker.service.schema.exceptions.InvalidSchemaDataException;\nimport org.apache.pulsar.client.impl.schema.ProtobufNativeSchemaUtils;\nimport org.apache.pulsar.common.protocol.schema.SchemaData;\n\npublic class ProtobufNativeSchemaDataValidator implements SchemaDataValidator {\n\n    @Override\n    public void validate(SchemaData schemaData) throws InvalidSchemaDataException {\n        Descriptors.Descriptor descriptor;\n        try {\n            descriptor = ProtobufNativeSchemaUtils.deserialize(schemaData.getData());\n        } catch (Exception e) {\n            throw new InvalidSchemaDataException(\"deserialize ProtobufNative Schema failed\", e);\n        }\n        if (descriptor == null) {\n            throw new InvalidSchemaDataException(\n                    \"protobuf root message descriptor is null,\"\n                            + \" please recheck rootMessageTypeName or rootFileDescriptorName conf. \");\n        }\n    }\n\n    public static ProtobufNativeSchemaDataValidator of() {\n        return INSTANCE;\n    }\n\n    private static final ProtobufNativeSchemaDataValidator INSTANCE = new ProtobufNativeSchemaDataValidator();\n\n    private ProtobufNativeSchemaDataValidator() {\n    }\n}\n","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/schema/validator/ProtobufNativeSchemaDataValidator.java#L16-L52","documentation":"ProtobufNativeSchemaDataValidator.validate deserializes the schema definition bytes as a Protobuf FileDescriptorSet via ProtobufNativeSchemaUtils.deserialize; any exception there is rethrown as InvalidSchemaDataException(\"deserialize ProtobufNative Schema failed\"). It means the schema data bytes are not a valid (parseable) FileDescriptorSet.","triggerScenarios":"Uploading a PROTOBUF_NATIVE schema whose data is not a serialized FileDescriptorSet — e.g. pasting the .proto text as schema data, sending an Avro/JSON blob with type PROTOBUF_NATIVE, or truncated/corrupted descriptor bytes.","commonSituations":"Hand-crafted admin REST calls where data was base64-encoded incorrectly; scripts that store the .proto source instead of the compiled descriptor; older client versions emitting a legacy descriptor format the broker cannot parse.","solutions":["Generate the schema info with the client API: Schema.PROTOBUF_NATIVE(MyProto.Msg.class) or ProtobufNativeSchema.of(...), which serializes the FileDescriptorSet correctly.","If building manually, serialize with ProtobufNativeSchemaUtils.serialize(rootMessageDescriptor) and base64/bytes it as-is.","Verify the bytes round-trip: ProtobufNativeSchemaUtils.deserialize(data) must succeed locally before uploading.","Confirm the client and broker use compatible Pulsar versions for the protobuf-native schema format."],"exampleFix":"// before\nSchemaInfo info = SchemaInfoImpl.builder().type(SchemaType.PROTOBUF_NATIVE)\n    .data(protoFileText.getBytes(UTF_8)).build(); // .proto text, not a descriptor set\n// after\nSchemaInfo info = Schema.PROTOBUF_NATIVE(com.example.MyMsg.class)\n    .getSchemaInfo(); // serialized FileDescriptorSet","handlingStrategy":"try-catch","validationCode":"try {\n    com.google.protobuf.Descriptors.FileDescriptor[] fds =\n        org.apache.pulsar.client.impl.schema.ProtobufNativeSchemaUtils.deserialize(info.getData());\n} catch (Exception e) {\n    throw new IllegalArgumentException(\"Schema data is not a valid FileDescriptorSet\", e);\n}","typeGuard":"boolean isProtoNativeSchemaInfo(SchemaInfo info) {\n    return info.getType() == SchemaType.PROTOBUF_NATIVE\n        && info.getData() != null && info.getData().length > 0;\n}","tryCatchPattern":"try {\n    admin.schemas().createSchema(topic, protoInfo);\n} catch (PulsarAdminException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"deserialize ProtobufNative Schema failed\")) {\n        // rebuild schema info via Schema.PROTOBUF_NATIVE(msgClass) and retry\n    } else {\n        throw e;\n    }\n}","preventionTips":["Always build protobuf-native schema info with Schema.PROTOBUF_NATIVE(Class) or ProtobufNativeSchema.of(...).","Never paste .proto source text as schema data; it must be the compiled FileDescriptorSet bytes.","Round-trip check the bytes locally (deserialize then compare descriptor names) before uploading."],"tags":["pulsar","protobuf","schema-validation"],"backgroundTag":"schema-deserialization-failed","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"}