Hi,
I have a schema defined as below

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *{  "type" : "record",  "name" : "DefRecord",  "namespace" :
> "com.test.ns1",  "doc" : "Message",  "fields" : [ {    "name" :
> "providerId",    "type" : {      "type" : "string",      "avro.java.string"
> : "String"    }  }, {    "name" : "defId",    "type" : {      "type" :
> "string",      "avro.java.string" : "String"    }    "default" : ""  }, {
>   "name" : "text",    "type" : [ "null", {      "type" : "string",
> "avro.java.string" : "String"    } ],    "doc" : "the text",    "default" :
> null  }, {    "name" : "count",    "type" : "int",    "doc" : "Number of
> segments in message",    "default" : 0  }, {    "name" : "defBytes",
> "type" : "bytes",    "default" : "ΓΏ"  } ]}*


I generated the classes using Java and using the builder tries to create an
object

DefRecord defRecord = DefRecord.newBuilder()
    .setProviderId("providerId")
    .setCount(1)
    .setDefId(null)
    .build();

The build runs successfully. (I expect this to fail as the field defId is
not nullable)

When I serialize this object it throws a NullPointerException

What I want to know is why the build is successful in the first place.
Shouldn't the build fail as we are trying to set a null value to a non
nullable field. Is there a reason for this behavior.

Thanks

Reply via email to