Details
-
Bug
-
Status: Resolved
-
Minor
-
Resolution: Duplicate
-
1.8.1
-
None
-
None
-
Windows 7, JDK8
Description
As per the summary, I had a search through the existing JIRAs but couldn't find a match apologies if this is a duplicate:
example schema:
{"namespace": "example.data", "type": "record", "name": "Data", "fields": [ {"name": "name", "type": "string"}, {"name": "favorite_season", "type": "string", "default": "Autumn"} ] }
GenericRecord record = new GenericData.Record(schema); record.put("name", "my name");
Serialising the above throws a NullPointerException:
java.lang.NullPointerException: null of string in field favorite_season of example.data.Data at org.apache.avro.generic.GenericDatumWriter.npe(GenericDatumWriter.java:145) ~[classes/:?] at org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:139) ~[classes/:?] at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:75) ~[classes/:?] at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:62) ~[classes/:?]
Surely, given that the schema is available the writeField method should check to see if there is a default field available to use if the required field does not have a value supplied (and is not-null).