You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Cédric Jäger (Jira)" <ji...@apache.org> on 2026/07/01 20:20:00 UTC
[jira] [Created] (AVRO-4273) The type of the default value must match with one element of the union
Cédric Jäger created AVRO-4273:
----------------------------------
Summary: The type of the default value must match with one element of the union
Key: AVRO-4273
URL: https://issues.apache.org/jira/browse/AVRO-4273
Project: Apache Avro
Issue Type: Bug
Components: java
Affects Versions: 1.12.1
Reporter: Cédric Jäger
Fix For: 1.12.2
The actual specification for [unions|https://avro.apache.org/docs/++version++/specification/#unions] states : "the type of the default value must match with *one* element of the union"
The actual implementation of the GenericData class on [line 1338|https://github.com/apache/avro/blob/840dc8139f4b3d1bfa8e8c8f1ac3be949b440634/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java#L1338], however, checks only for the first element of the union :
{code:java}
if (json.isNull() && (field.schema().getType() == Type.NULL
|| (field.schema().getType() == Type.UNION && field.schema().getTypes().get(0).getType() == Type.NULL))) {
return null;
} {code}
This causes a problem when there is a nullable field with a default value of null and null is not defined as the first element of the union in the schema :
Instead, the code should iterate through the elements of the union to check if one of them is of type NULL, and return null if it is.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)