[
https://issues.apache.org/jira/browse/AVRO-1801?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Thiruvalluvan M. G. updated AVRO-1801:
--------------------------------------
Component/s: java
> Generated code results in java.lang.ClassCastException
> ------------------------------------------------------
>
> Key: AVRO-1801
> URL: https://issues.apache.org/jira/browse/AVRO-1801
> Project: Apache Avro
> Issue Type: Bug
> Components: java
> Affects Versions: 1.8.0
> Reporter: Alex Baumgarten
> Priority: Major
>
> 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
(v7.6.3#76005)