Skip to content

AVRO-4238: [java] Fix Schema Evolution of Unions with an Array Default Value#3730

Merged
RyanSkraba merged 1 commit intoapache:mainfrom
cedricholzer:avro-4238-fix-union-with-empty-array-default
May 7, 2026
Merged

AVRO-4238: [java] Fix Schema Evolution of Unions with an Array Default Value#3730
RyanSkraba merged 1 commit intoapache:mainfrom
cedricholzer:avro-4238-fix-union-with-empty-array-default

Conversation

@cedricholzer
Copy link
Copy Markdown
Contributor

@cedricholzer cedricholzer commented Apr 12, 2026

What is the purpose of the change

When FastReader is enabled and a field of type union<array<?>> with an array as default value is added, the Schema Evolution fails and throws an AvroRuntimeException (for more details see AVRO-4238).

This change fixes the root cause of the bug in FastReaderBuilder.java. If the field schema is of type Union, then the first nested Array type is unboxed and passed to GenericData::newArray (which expects an Array schema) instead of the Union schema.

While touching TestReadingWritingDataInEvolvedSchemas.java, this PR also removes unused imports and consistently uses org.junit.jupiter.api.Assertions like the rest of the project instead of mixing it with org.junit.Assert.

Verifying this change

This change added tests and can be verified as follows:

  • Added a test case that tests Schema Evolution while adding a new field of type union<array<>> = []. This test reproduces the bug on main, throwing an AvroRuntimeException, but passes on the fixed branch.

Documentation

This PR does not introduce new features. No documentation was added or edited.

@github-actions github-actions Bot added the Java Pull Requests for Java binding label Apr 12, 2026
When FastReader was enabled and a field of type Union<Array, ...>
with an Array as default value was added, an AvroRuntimeException
occurred during Schema Evolution.

This change resolves this bug in FastReaderBuilder.java, allowing the
Schema Migration to succeed as specified.
@cedricholzer cedricholzer force-pushed the avro-4238-fix-union-with-empty-array-default branch from 78bc7da to 9f70011 Compare April 12, 2026 21:57
@RyanSkraba RyanSkraba changed the title Avro-4238: [java] Fix Schema Evolution of Unions with an Array Default Value AVRO-4238: [java] Fix Schema Evolution of Unions with an Array Default Value May 7, 2026
Copy link
Copy Markdown
Contributor

@RyanSkraba RyanSkraba left a comment

Choose a reason for hiding this comment

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

OK, this LGTM -- it's a good catch, and the parallel problem shouldn't occur in Map (for example) because you don't need the schema to create a new, empty map. Thanks for the contribution!

@RyanSkraba RyanSkraba merged commit 892d699 into apache:main May 7, 2026
9 checks passed
RyanSkraba pushed a commit that referenced this pull request May 7, 2026
…3730)

When FastReader was enabled and a field of type Union<Array, ...>
with an Array as default value was added, an AvroRuntimeException
occurred during Schema Evolution.

This change resolves this bug in FastReaderBuilder.java, allowing the
Schema Migration to succeed as specified.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Java Pull Requests for Java binding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants