Skip to content

[Java] Fix NullPointerException in protobuf FieldBuilder for schemas without parameters#518

Open
jvdadda wants to merge 2 commits intoawslabs:masterfrom
mobsuccess-devops:fix/protobuf-converter-npe
Open

[Java] Fix NullPointerException in protobuf FieldBuilder for schemas without parameters#518
jvdadda wants to merge 2 commits intoawslabs:masterfrom
mobsuccess-devops:fix/protobuf-converter-npe

Conversation

@jvdadda
Copy link
Copy Markdown

@jvdadda jvdadda commented Mar 12, 2026

Issue #, if available: Fixes #289

Description of changes:

When using Debezium or other Kafka Connect source connectors with ProtobufSchemaConverter, a NullPointerException is thrown in FieldBuilder.build() because fieldSchema.parameters() can return null for STRUCT-type fields that don't carry protobuf metadata.

This PR adds null guards in two places in FieldBuilder.java:

  • Check fieldSchema.parameters() != null before calling .containsKey(PROTOBUF_TYPE) (line 92)
  • Check fieldSchema.name() != null before passing it to getSchemaSimpleName() and isParentLevel(), falling back to the field name for unnamed struct schemas

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Add null checks for fieldSchema.parameters() and fieldSchema.name()
in the STRUCT type handling of FieldBuilder.build() to prevent NPE
when used with Debezium or other connectors that produce schemas
without protobuf metadata parameters or without schema names.
Copilot AI review requested due to automatic review settings March 12, 2026 22:59
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a NullPointerException encountered when converting Kafka Connect STRUCT schemas to Protobuf (notably with Debezium), by adding null guards around schema metadata access in FieldBuilder.

Changes:

  • Guard against fieldSchema.parameters() being null before checking protobuf metadata.
  • Guard against fieldSchema.name() being null when deriving nested message names and when deciding whether to emit a top-level vs nested message.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

unnamed structs, add test for null parameters/name
@jvdadda
Copy link
Copy Markdown
Author

jvdadda commented Mar 12, 2026

Addressed all three Copilot review comments in 5f7ac70:

  1. Local variable for parameters(): Extracted to fieldParameters and simplified the condition using PROTOBUF_ONEOF_TYPE.equals(fieldParameters.get(PROTOBUF_TYPE))
  2. typeName NPE for unnamed structs: Fixed getFieldDescriptorProtoBuilder to construct a fully qualified type name from the parent message context when fieldSchema.name() is null
  3. Missing test: Added fromConnectSchema_structWithNullParametersAndName_doesNotThrowNPE covering a STRUCT with null parameters and null name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ConnectSchemaToProtobufSchemaConverter throws NullPointerException

2 participants