Thanks, it looks related.
but I guess this is a new issue?
the following change fixed the issue:
--- SpecificRecordBase.java 2009-10-09 14:13:22.000000000 -0700
+++ /tmp/SpecificRecordBase.java 2010-02-07 23:00:53.000000000 -0800
@@ -58,8 +58,10 @@
static int hashCode(SpecificRecord r) {
int result = 0;
int end = r.getSchema().getFields().size();
- for (int i = 0; i < end; i++)
+ for (int i = 0; i < end; i++){
+ if ( r.get(i) != null )
result += r.get(i).hashCode();
+ }
return result;
}
On Sun, Feb 7, 2010 at 10:55 PM, Michael Armbrust <
[email protected]> wrote:
> 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 <[email protected]> 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
>>
>
>