[
https://issues.apache.org/jira/browse/AVRO-4225?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
ASF GitHub Bot updated AVRO-4225:
---------------------------------
Labels: pull-request-available (was: )
> GenericDatumReader throws ClassCastException for schemas with "java-class"
> attribute on string fields
> -----------------------------------------------------------------------------------------------------
>
> Key: AVRO-4225
> URL: https://issues.apache.org/jira/browse/AVRO-4225
> Project: Apache Avro
> Issue Type: Bug
> Affects Versions: 1.12.1
> Reporter: Kevin Burke
> Priority: Minor
> Labels: pull-request-available
> Time Spent: 10m
> Remaining Estimate: 0h
>
> A minimal reproduction test case can be found here:
> https://github.com/apache/avro/pull/3616
> When deserializing records using {{GenericDatumReader}} with schemas that
> have a {{"java-class"}} attribute on string fields (e.g., {{{}"java-class":
> "java.math.BigDecimal"{}}}), Avro throws a {{{}ClassCastException{}}}.
> *Schema example:*
>
> {{{
> "type": "record",
> "name": "TestRecord",
> "fields": [
> \{"name": "price", "type": ["null", {
> "type": "string",
> "java-class": "java.math.BigDecimal"
> }]}
> ]
> }}}
> *Stack trace:*
>
> {{java.lang.ClassCastException: class org.apache.avro.util.Utf8 cannot be
> cast to class java.lang.String
> at
> org.apache.avro.io.FastReaderBuilder.lambda$getTransformingStringReader$32(FastReaderBuilder.java:440)
> at
> org.apache.avro.io.FastReaderBuilder.lambda$createUnionReader$30(FastReaderBuilder.java:412)
> at
> org.apache.avro.io.FastReaderBuilder.lambda$createFieldSetter$1(FastReaderBuilder.java:181)
> at
> org.apache.avro.io.FastReaderBuilder$RecordReader.read(FastReaderBuilder.java:575)
> at
> org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:150)}}
> *Root cause:*
> In {{FastReaderBuilder.getTransformingStringReader()}} (line 440), the code
> casts the result of {{stringReader.read()}} directly to {{{}String{}}}:
>
> {{return (old, decoder) -> transformer.apply((String) stringReader.read(null,
> decoder));}}
> However, when using {{{}GenericData{}}}, the string reader returns
> {{{}Utf8{}}}, not {{{}String{}}}. This causes the {{{}ClassCastException{}}}.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)