Skip to content

[Java] Fix null default values in Avro KafkaConnect converter#517

Open
jvdadda wants to merge 2 commits intoawslabs:masterfrom
mobsuccess-devops:fix/avro-null-default-value
Open

[Java] Fix null default values in Avro KafkaConnect converter#517
jvdadda wants to merge 2 commits intoawslabs:masterfrom
mobsuccess-devops:fix/avro-null-default-value

Conversation

@jvdadda
Copy link
Copy Markdown

@jvdadda jvdadda commented Mar 12, 2026

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() throws DataException: 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_VALUE in toConnectData(), consistent with the existing check in defaultValueFromAvroWithoutLogical() (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.

Handle JsonProperties.NULL_VALUE in toConnectData() to prevent
DataException when record defaults contain null values (e.g. optional
union fields with null default).
Copilot AI review requested due to automatic review settings March 12, 2026 22:55
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 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_VALUE as null in AvroData.toConnectData(...) to prevent DataException during default conversion.
  • Add a regression test covering a record default object that includes a nested null field 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.
@jvdadda
Copy link
Copy Markdown
Author

jvdadda commented Mar 12, 2026

Addressed Copilot review: updated validateSchemaValue to treat JsonProperties.NULL_VALUE as null-equivalent, so non-optional schemas still correctly reject it (b5ce96c).

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.

Kafka Connect converter fails when schema contains null default values for record field

2 participants