You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by "JohnMTu (Jira)" <ji...@apache.org> on 2025/06/03 09:10:00 UTC

[jira] [Updated] (AVRO-4148) serializing enums containing java keywords fails in NPE

     [ https://issues.apache.org/jira/browse/AVRO-4148?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

JohnMTu updated AVRO-4148:
--------------------------
    Affects Version/s: 1.10.1
                       1.12.1

> serializing enums containing java keywords fails in NPE
> -------------------------------------------------------
>
>                 Key: AVRO-4148
>                 URL: https://issues.apache.org/jira/browse/AVRO-4148
>             Project: Apache Avro
>          Issue Type: Bug
>    Affects Versions: 1.10.1, 1.12.1
>            Reporter: JohnMTu
>            Priority: Major
>         Attachments: AvroIssueTest.java
>
>
> when having schema containing enum with enum-values like "new", "boolean", "null" which are java reserved keyword, then enum-value is generated with $ suffix using avro-maven-plugin.
> When i later try to serialize it to json, it fails on NPE.
> Normally i have similar enum deep in structure, and avro-maven-plugin is used. For simplicity of testcase, i copied generated class into test itself and instead of using massive structure i reproduce the problem when serializing enum itself.
> See attached test case. This is log output:
> {code:java}
> java.lang.NullPointerException: null value for (non-nullable) RecurringChargePeriod    at org.apache.avro.path.TracingNullPointException.summarize(TracingNullPointException.java:88)
>     at org.apache.avro.path.TracingNullPointException.summarize(TracingNullPointException.java:30)
>     at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:84)
>     at AvroIssueTest.serializeWrappedEnumToJson(AvroIssueTest.java:56)
>     at java.base/java.lang.reflect.Method.invoke(Method.java:580)
>     at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
>     at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
> Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.Integer.intValue()" because the return value of "java.util.Map.get(Object)" is null
>     at org.apache.avro.Schema$EnumSchema.getEnumOrdinal(Schema.java:1098)
>     at org.apache.avro.generic.GenericDatumWriter.writeEnum(GenericDatumWriter.java:272)
>     at org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:148)
>     at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:95)
>     at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:82)
>     ... 4 more {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)