You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Alex Baumgarten (JIRA)" <ji...@apache.org> on 2016/02/19 01:11:18 UTC

[jira] [Created] (AVRO-1801) Generated code results in java.lang.ClassCastException

Alex Baumgarten created AVRO-1801:
-------------------------------------

             Summary: Generated code results in java.lang.ClassCastException
                 Key: AVRO-1801
                 URL: https://issues.apache.org/jira/browse/AVRO-1801
             Project: Avro
          Issue Type: Bug
    Affects Versions: 1.8.0
            Reporter: Alex Baumgarten


Create and compile avro schema:
{
    "namespace": "com.abc.def.ghi.schema",
    "type": "record",
    "name": "MyDataRecord",
    "fields": [
        {"name": "Heading", "type": ["null", {"type": "fixed", "name": "short", "size": 2}]}
    ]
}

which leads to compiled code:

public void put(int field$, java.lang.Object value$) {
  switch (field$) {
  case 0: Heading = (com.abc.def.ghi.schema.short$)value$; break;
  default: throw new org.apache.avro.AvroRuntimeException("Bad index");
  }
}

When this function is called the type of value is org.apache.avro.generic.GenericData$Fixed and when it tries to cast to the short$ type it throws a java.lang.ClassCastException.

This occurs when running the following code:
SpecificDatumReader<MyDataRecord> datumReader = new SpecificDatumReader<>(MyDataRecord.class);
DataFileReader<MyDataRecord> dataFileReader = new DataFileReader<>(new FsInput(inputAvroPath, configuration), datumReader);

for (MyDataRecord record : dataFileReader) {
    // Do something with record
}


If I manually modify the generated code to extract the bytes from value$ and call the constructor of short$ it works as expected. But this is not what is generated.





--
This message was sent by Atlassian JIRA
(v6.3.4#6332)