[Java] Fix null default values in Avro KafkaConnect converter#517
Open
jvdadda wants to merge 2 commits intoawslabs:masterfrom
Open
[Java] Fix null default values in Avro KafkaConnect converter#517jvdadda wants to merge 2 commits intoawslabs:masterfrom
jvdadda wants to merge 2 commits intoawslabs:masterfrom
Conversation
Handle JsonProperties.NULL_VALUE in toConnectData() to prevent DataException when record defaults contain null values (e.g. optional union fields with null default).
There was a problem hiding this comment.
Pull request overview
Fixes a Kafka Connect Avro converter failure when Avro record field default values contain null (represented by JsonProperties.NULL_VALUE), aligning behavior with Confluent’s avro-data fix and addressing issue #307.
Changes:
- Treat
JsonProperties.NULL_VALUEasnullinAvroData.toConnectData(...)to preventDataExceptionduring default conversion. - Add a regression test covering a record default object that includes a nested
nullfield value.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
avro-kafkaconnect-converter/src/main/java/com/amazonaws/services/schemaregistry/kafkaconnect/avrodata/AvroData.java |
Adds JsonProperties.NULL_VALUE handling in toConnectData(...) to avoid type-cast failures during default conversion. |
avro-kafkaconnect-converter/src/test/java/com/amazonaws/services/schemaregistry/kafkaconnect/avrodata/AvroDataNullDefaultTest.java |
Introduces a regression test reproducing issue #307’s schema-default-with-null scenario. |
💡 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.
Ensures non-optional schemas still reject NULL_VALUE consistently with how they reject Java null.
Author
|
Addressed Copilot review: updated |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #, if available: Fixes #307
Description of changes:
When an Avro record field has a default value containing
null(e.g., an optional union field like"en": null),AvroData.toConnectData()throwsDataException: Invalid class for string type, expecting String or CharSequence but found class org.apache.avro.JsonProperties$Null.The fix adds a check for
JsonProperties.NULL_VALUEintoConnectData(), consistent with the existing check indefaultValueFromAvroWithoutLogical()(line 1890). This is the same fix applied in the Confluent schema registry (PR #1928).By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.