Home | About | Sematext search-lucene.com search-hadoop.com
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB
 Search Hadoop and all its subprojects:

Switch to Threaded View
Avro >> mail # dev >> Explaining NullPointerException


Copy link to this message
-
Re: Explaining NullPointerException
Hey John

Please file a JIRA at https://issues.apache.org/jira/browse/AVRO requesting
that this error message be clarified, and we'll get to it right away (see
https://issues.apache.org/jira/browse/AVRO-583, for example, for similar
such clarifications requested and implemented).

Thanks,
Jeff

On Fri, Aug 13, 2010 at 5:39 PM, John Kristian <[EMAIL PROTECTED]>wrote:

> When one writes an erroneous null datum, it would be helpful for the stack
> trace to say more about what happened; for example:
>
> java.lang.NullPointerException: MyRecord.myField
>    at ...
> Caused by: java.lang.NullPointerException: string
>    at ...
>
> Is someone working to implement something like this?
>
> One can make a subclass of SpecificDatumWriter to do this, but one must
> copy-n-paste GenericDatumWriter.writeRecord.  It could be done without
> copy-n-pasting, if GenericDatumWriter.writeRecord were split into two
> methods:
>
>  protected void writeRecord(Schema schema, Object datum, Encoder out)
>    throws IOException {
>    for (Field field : schema.getFields()) {
>      writeField(schema, datum, field, out);
>    }
>  }
>
>  protected void writeField(Schema schema, Object datum, Field field,
> Encoder out)
>    throws IOException {
>    write(field.schema(), getField(datum, field.name(), field.pos()), out);
>  }
>
> Then the subclass could override two methods:
>
>  @Override
>  protected void writeField(Schema schema, Object datum, Field field,
> Encoder out)
>    throws IOException {
>    try {
>      super.writeField(schema, datum, field, out);
>    } catch (NullPointerException e)  {
>      NullPointerException e2 >        new NullPointerException(schema.getName() + "." + field.name());
>      e2.initCause(e);
>      throw e2;
>    }
>  }
>
>  @Override
>  protected void write(Schema schema, Object datum, Encoder out)
>    throws IOException {
>    switch (schema.getType()) {
>    case UNION:
>    case NULL:
>      break;
>    default:
>      if (datum == null)
>        throw new NullPointerException(schema.getName());
>    }
>    super.write(schema, datum, out);
>  }
>
> - John Kristian
>
>
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB