JohnMTu created AVRO-4148: ----------------------------- Summary: 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 Reporter: JohnMTu 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)