You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Muhammad Asif Tasleem (JIRA)" <ji...@apache.org> on 2019/04/17 00:28:00 UTC

[jira] [Created] (AVRO-2376) Null Pointer Exception

Muhammad Asif Tasleem created AVRO-2376:
-------------------------------------------

             Summary: Null Pointer Exception
                 Key: AVRO-2376
                 URL: https://issues.apache.org/jira/browse/AVRO-2376
             Project: Apache Avro
          Issue Type: Bug
          Components: java
    Affects Versions: 1.8.2
            Reporter: Muhammad Asif Tasleem


GenericDatumWriter throws an NPE at line# 67 if datum is null:

 

 

  @Override

  *protected* *void* writeString(Schema schema, Object datum, Encoder out)

    *throws* IOException {

    {color:#d04437}*if* (!(datum *instanceof* CharSequence){color}

{color:#d04437}        && getSpecificData().isStringable(datum.getClass())) {{color}

      datum = datum.toString();                   // convert to string

    }

    writeString(datum, out);

  }

 

 

The condition that is being verified in GenericDatumWriter at line # 69 should be broken to handle the case when datum is null:

/** Called to write data.*/

  *protected* *void* write(Schema schema, Object datum, Encoder out)

      *throws* IOException {

    LogicalType logicalType = schema.getLogicalType();

    {color:#d04437}*if* (datum != *null* && logicalType != *null*) {{color}

      Conversion<?> conversion = getData()

          .getConversionByClass(datum.getClass(), logicalType);

      writeWithoutConversion(schema,

          convert(schema, logicalType, conversion, datum), out);

    } *else* {

      writeWithoutConversion(schema, datum, out);

    }

  }



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)