[ 
https://issues.apache.org/jira/browse/AVRO-382?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12805583#action_12805583
 ] 

Philip Zeyliger commented on AVRO-382:
--------------------------------------

I just committed this.  Thanks, Michael!

> hashCode throws a NullPointerException when fields are uninitialized
> --------------------------------------------------------------------
>
>                 Key: AVRO-382
>                 URL: https://issues.apache.org/jira/browse/AVRO-382
>             Project: Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.2.0
>            Reporter: Michael Armbrust
>            Priority: Minor
>         Attachments: hashCodeTest.diff, hashFix.diff
>
>
> When you call hashCode on an Avro Record with unitialized fields the method 
> throws a NullPointerException.  This is especially troublesome if you are 
> trying to instantiate an object from an interactive console (like scala), as 
> this makes it impossible to create records.  Here is an example, where KVPair 
> is defined as follows:
> {noformat}
> {
>       "namespace": "edu.berkeley.cs.scads",
>       "protocol": "Storage",
>       "types": [
>               {"name": "KVPair", "type": "record", "fields": [
>                       {"name": "key", "type": "string"},
>                       {"name": "value", "type": "string"}]
>               }
>       ]
> }
> {noformat}
> And the error:
> {noformat} 
> scala> val x = new edu.berkeley.cs.scads.KVPair
> val x = new edu.berkeley.cs.scads.KVPair
> java.lang.NullPointerException
>       at 
> org.apache.avro.specific.SpecificRecordBase.hashCode(SpecificRecordBase.java:62)
>       at 
> org.apache.avro.specific.SpecificRecordBase.hashCode(SpecificRecordBase.java:55)
>       at edu.berkeley.cs.scads.KVPair.hashCode(Record.java:50001)
>       at java.lang.Object.toString(Object.java:219)
>       at edu.berkeley.cs.scads.KVPair.toString(Record.java:50001)
>       at scala.runtime.ScalaRunTime$.stringOf(ScalaRunTime.scala:165)
>       at RequestResult$.<init>(<console>:4)
>       at RequestResult$.<clinit>(<console>)
>       at RequestResult$result(<console>)
>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>       at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>       at java.lang.reflect.Method.invoke(Method.java:597)
>       at scala.tools.nsc.Interpreter$Request.loadAndRun(Interpreter.scala:889)
>       at scala.tools.nsc.Interpreter.interpret(Interpreter.scala:508)
>       at 
> scala.tools.nsc.InterpreterLoop.interpretStartingWith(InterpreterLoop.scala:242)
>       at scala.tools.nsc.InterpreterLoop.command(InterpreterLoop.scala:230)
>       at scala.tools.nsc.InterpreterLoop.repl(InterpreterLoop.scala:142)
>       at scala.tools.nsc.InterpreterLoop.main(InterpreterLoop.scala:298)
>       at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:141)
>       at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
> {noformat} 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to