[jira] [Commented] (AVRO-1927) If a default value is set, Avro allows null values in non-nullable fields.

2016-09-25 Thread Yibing Shi (JIRA)

[ 
https://issues.apache.org/jira/browse/AVRO-1927?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15522012#comment-15522012
 ] 

Yibing Shi commented on AVRO-1927:
--

[~asmaier], currently the generated code doesn't check whether we are setting a 
null value for a non nullable column. In your case, null is a valid Java String 
value and thus it works. However, I believe AVRO would throw an exception when 
you try to write your object. Have you tried that? Does it fail or succeed?

{code}
ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
Encoder encoder = EncoderFactory.get().binaryEncoder(os, null);
SpecificDatumWriter writer = new 
SpecificDatumWriter(MyObject.getClassSchema());
writer.write(myObject, encoder);
{code}

> If a default value is set, Avro allows null values in non-nullable fields.
> --
>
> Key: AVRO-1927
> URL: https://issues.apache.org/jira/browse/AVRO-1927
> Project: Avro
>  Issue Type: Bug
>  Components: java
>Affects Versions: 1.8.1
>Reporter: Andreas Maier
>  Labels: newbie
>
> With an avro schema like
> {code}
> {
>   "name": "myfield",
>   "type": "string",
>   "default": ""
> }
> {code}
> the following code should throw an exception
> {code}
> MyObject myObject = MyObject.newBuilder().setMyfield(null).build();
> {code}
> But instead the value of myfield is set to null, which causes an exception 
> later when serializing myObject, because null is not a valid value for 
> myfield. 
> I believe in this case setMyfield(null) should throw an exception, 
> independent of the value of default. 
> See also
> https://stackoverflow.com/questions/38509279/generated-avro-builder-set-null-doesnt-overwrite-with-default



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


New Contributor

2016-09-25 Thread Thilina Manamgoda
Hi,

I am Thilina Manamgoda an undergraduate of faculty of engineering,
university of peradeniya, Sri Lanka. I would like to get involved in this
project to help as much as i can.



Regards,
Thilina