{"record":{"id":"9e9b96b31b6d0386","repo":"apache/druid","slug":"fail-to-get-protobuf-schema-because-of-invalid-sch","errorCode":null,"errorMessage":"Fail to get protobuf schema because of invalid schema!","messagePattern":"Fail to get protobuf schema because of invalid schema!","errorType":"exception","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"extensions-core/protobuf-extensions/src/main/java/org/apache/druid/data/input/protobuf/SchemaRegistryBasedProtobufBytesDecoder.java","lineNumber":195,"sourceCode":"    int id = bytes.getInt(); // extract schema registry id\n    bytes.get(); // ignore \\0 byte before PB message\n    int length = bytes.limit() - 2 - 4;\n    Descriptors.Descriptor descriptor;\n    try {\n      ProtobufSchema schema = (ProtobufSchema) registry.getSchemaById(id);\n      descriptor = schema.toDescriptor();\n    }\n    catch (RestClientException e) {\n      LOGGER.error(e.getMessage());\n      throw new ParseException(\n          null,\n          e,\n          \"Fail to get protobuf schema because of can not connect to registry or failed http request!\"\n      );\n    }\n    catch (IOException e) {\n      LOGGER.error(e.getMessage());\n      throw new ParseException(null, e, \"Fail to get protobuf schema because of invalid schema!\");\n    }\n    try {\n      byte[] rawMessage = new byte[length];\n      bytes.get(rawMessage, 0, length);\n      return DynamicMessage.parseFrom(descriptor, rawMessage);\n    }\n    catch (Exception e) {\n      LOGGER.error(e.getMessage());\n      throw new ParseException(null, e, \"Fail to decode protobuf message!\");\n    }\n  }\n\n  @Override\n  public boolean equals(Object o)\n  {\n    if (this == o) {\n      return true;\n    }","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/protobuf-extensions/src/main/java/org/apache/druid/data/input/protobuf/SchemaRegistryBasedProtobufBytesDecoder.java#L177-L213","documentation":"After fetching the schema by id, the decoder converts it to a protobuf Descriptor via schema.toDescriptor(). If that fails with an IOException, the stored schema is not a usable/valid protobuf schema, and Druid throws a ParseException with this message.","triggerScenarios":"registry.getSchemaById succeeds but ProtobufSchema.toDescriptor() throws IOException — the schema stored under the id is not a valid protobuf schema (e.g. registered as Avro/JSON in the same registry, or corrupt schema text).","commonSituations":"Using this decoder against a registry where subjects were registered with the wrong serialization format; manually edited or corrupted schema entries; protobufSchemaProvider misconfiguration.","solutions":["Confirm the subject/schema for the consumed ids was registered with the PROTOBUF format, not Avro/JSON","Re-register the correct .proto schema under the subject and republish or use the correct schema id","Check that ProtobufSchemaProvider is configured in the decoder and registry compatibility settings allow the protobuf type"],"exampleFix":"// before: subject registered as AVRO\n$ kafka-avro-console-producer --property schema.registry.url=...\n// after: register protobuf schema\ncurl -X POST http://registry:8081/subjects/mytopic-value/versions -H 'Content-Type: application/vnd.schemaregistry.v1+json' -d '{\"schemaType\":\"PROTOBUF\",\"schema\":\"syntax=\\\"proto3\\\"; message Msg { ... }\"}'","handlingStrategy":"validation","validationCode":"Schema schema = registry.getSchemaById(id);\nif (!(schema instanceof ProtobufSchema)) {\n  throw new IllegalStateException(\"Schema id \" + id + \" is not PROTOBUF type: \" + schema.schemaType());\n}","typeGuard":null,"tryCatchPattern":"try {\n  byte[] parsed = decoder.parse(bytes);\n} catch (ParseException e) {\n  if (e.getMessage().contains(\"invalid schema\")) {\n    log.error(\"Registered schema for id is not a valid protobuf schema; re-register with schemaType=PROTOBUF\", e.getCause());\n  }\n}","preventionTips":["Register subjects explicitly with schemaType=PROTOBUF","Reject Avro/JSON-schema producers writing to topics consumed by this decoder","Validate registry contents with a script that decodes each schema id as ProtobufSchema"],"tags":["schema-registry","protobuf","schema-validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}