linkedin / rest.li

Rest.li is a REST+JSON framework for building robust, scalable service architectures using dynamic discovery and simple asynchronous APIs.
rest.li
Other
2.51k stars 546 forks source link

Bugfix for Avro schema translation for schemas with partial record default values #778

Closed thomaskistler closed 2 years ago

thomaskistler commented 2 years ago

This commit fixes a bug for record default values that do not specify default values for each field. If a field is optional and is missing a default value in the record default value, fieldValue in translateField() will be null instead of Data.NULL.

Without this fix, Avro schema translation will fail with a NullPointerException.

java.lang.NullPointerException
    at com.linkedin.data.avro.AbstractDefaultDataTranslator.translate(AbstractDefaultDataTranslator.java:136)
    at com.linkedin.data.avro.DefaultAvroToDataConvertCallback.translateField(DefaultAvroToDataConvertCallback.java:88)
    at com.linkedin.data.avro.AbstractDefaultDataTranslator.translate(AbstractDefaultDataTranslator.java:138)
    at com.linkedin.data.avro.DefaultAvroToDataConvertCallback.translateField(DefaultAvroToDataConvertCallback.java:88)
    at com.linkedin.data.avro.DefaultAvroToDataConvertCallback.callback(DefaultAvroToDataConvertCallback.java:38)
    at com.linkedin.data.schema.DataSchemaTraverse.traverseRecurse(DataSchemaTraverse.java:92)
    at com.linkedin.data.schema.DataSchemaTraverse.traverse(DataSchemaTraverse.java:75)
    at com.linkedin.data.schema.DataSchemaTraverse.traverse(DataSchemaTraverse.java:64)
    at com.linkedin.data.avro.SchemaTranslator.avroToDataSchema(SchemaTranslator.java:184)
    at com.linkedin.data.avro.SchemaTranslator.avroToDataSchema(SchemaTranslator.java:238)