Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
1.9.2, 1.11.3
-
None
-
None
-
Important
Description
In our company we're using both 1.9.2 and 1.11.3 versions of avro compiling to Java 8 (or 11) and in both cases we have observed that bug AVRO-1981 is still active and deserialization fails for nullable fields that have a logical type: happens at least for both "uuid" (in version 1.11.3, previous one just ignores this type) and "timestamp-millis" (in both versions).
The fields are defined as follows:
//(...) { "name": "requestId", "type": [ "null", { "type": "string", "logicalType": "uuid" } ], "default": null } //(...) { "name": "upperTimeLimit", //"doc" field "type": [ "null", { "type": "long", "logicalType": "timestamp-millis" } ], "default": null }
The error we get for the uuid case when attempting to deserialize is:
java.lang.ClassCastException: class org.apache.avro.util.Utf8 cannot be cast to class java.util.UUID
In the generated class file we should be getting:
private static final org.apache.avro.Conversion<?>[] conversions; //(...) static { MODEL$.addLogicalTypeConversion(new Conversions.UUIDConversion()); MODEL$.addLogicalTypeConversion(new TimeConversions.TimestampMillisConversion()); ENCODER = new BinaryMessageEncoder(MODEL$, SCHEMA$); DECODER = new BinaryMessageDecoder(MODEL$, SCHEMA$); conversions = new org.apache.avro.Conversion<?>[] { null, null, new org.apache.avro.Conversions.UUIDConversion(), null, new org.apache.avro.data.TimeConversions.TimestampMillisConversion(), null }; WRITER$ = MODEL$.createDatumWriter(SCHEMA$); READER$ = MODEL$.createDatumReader(SCHEMA$); }
but we get:
static { MODEL$.addLogicalTypeConversion(new Conversions.UUIDConversion()); MODEL$.addLogicalTypeConversion(new TimeConversions.TimestampMillisConversion()); ENCODER = new BinaryMessageEncoder(MODEL$, SCHEMA$); DECODER = new BinaryMessageDecoder(MODEL$, SCHEMA$); WRITER$ = MODEL$.createDatumWriter(SCHEMA$); READER$ = MODEL$.createDatumReader(SCHEMA$); }
Both the definition and the initialization of the conversions field are missing.