Skip to content

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

Open
cedricholzer wants to merge 1 commit intoapache:mainfrom
cedricholzer:avro-4238-fix-union-with-empty-array-default
Open

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

Conversation

@cedricholzer
Copy link
Copy Markdown

@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
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.

1 participant