avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Armbrust <michael.armbr...@gmail.com>
Subject Re: null gives error
Date Mon, 08 Feb 2010 06:55:35 GMT
This is probably related to the following issues (both fixed in trunk):

https://issues.apache.org/jira/browse/AVRO-382
https://issues.apache.org/jira/browse/AVRO-387

Michael

On Sun, Feb 7, 2010 at 10:46 PM, Yang <teddyyyy123@gmail.com> wrote:

> I defined my fields to be optional, i.e. with a schema of a union of null
> and my proper type
>
>
> {
>
>     "name" : "Yytest",
>     "namespace" : "com.yahoo.enc.avro",
>
>     "type" : "record",
>
>     "fields" : [
>     { "name" : "f1" , "type" : [{ "type" : "array", "items" : "long" },
> "null" ] },
>     { "name" : "f2", "type" : [ "int", "null"] }
>     ]
>
> }
>
>
> then
> in java code, I tried to print out the record without assigning value to
> either f1 or f2
>
>         Yytest y = new Yytest();
>         y.f2 = 1;
>         y.f1 = new GenericData.Array(10, null);
>
>         System.out.println(y.toString());
>
>
>
> taking out either of the f1 or f2 assignments would lead to the following
> error:
>      [java] Exception in thread "main" java.lang.NullPointerException
>      [java]     at
> org.apache.avro.specific.SpecificRecordBase.hashCode(SpecificRecordBase.java:62)
>      [java]     at
> org.apache.avro.specific.SpecificRecordBase.hashCode(SpecificRecordBase.java:55)
>      [java]     at java.lang.Object.toString(Object.java:219)
>      [java]     at
> com.yahoo.enc.avro.AvroGdserve.main(AvroGdserve.java:259)
>      [java] Java Result: 1
>
>
>
>
>
>
> doesn't the "null" allow a field to be optional ?
>
>
> Thanks
> Yang
>

Mime
View raw message