You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by "Cédric Jäger (Jira)" <ji...@apache.org> on 2026/08/09 16:44:00 UTC
[jira] [Commented] (AVRO-4273) The type of the default value must match with one element of the union
[ https://issues.apache.org/jira/browse/AVRO-4273?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18103162#comment-18103162 ]
Cédric Jäger commented on AVRO-4273:
------------------------------------
Added Java classes that will correct this problem. I tried to open a pull request, but got an error...
> 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
> Priority: Minor
> Fix For: 1.13.0
>
> Attachments: GenericData.java, GenericDataTest.java
>
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> 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)