Skip to content

Conversation

@kevinburkesegment
Copy link

@kevinburkesegment kevinburkesegment commented Jan 7, 2026

What is the purpose of the change

When using GenericDatumReader with schemas containing "java-class" attributes on string fields (e.g., java.math.BigDecimal), FastReaderBuilder throws:

ClassCastException: Utf8 cannot be cast to String

The bug is in getTransformingStringReader() which casts the result of stringReader.read() directly to String, but GenericData returns Utf8.

This commit adds a failing test to reproduce the issue.

Verifying this change

Run the test suite.

Documentation

  • Does this pull request introduce a new feature? No

@github-actions github-actions bot added the Java Pull Requests for Java binding label Jan 7, 2026
@kevinburkesegment
Copy link
Author

I'd be happy to try and propose a fix as well but I'm not great at Java

…th java-class attribute

When using GenericDatumReader with schemas containing "java-class"
attributes on string fields (e.g., java.math.BigDecimal),
FastReaderBuilder throws:

    ClassCastException: Utf8 cannot be cast to String

The bug is in getTransformingStringReader() which casts the result of
stringReader.read() directly to String, but GenericData returns Utf8.

This commit adds a failing test to reproduce the issue.
@m8719-github
Copy link

m8719-github commented Jan 11, 2026

Just run into what looks to be a related issue with decimal logical type:

java.lang.ClassCastException: class java.math.BigDecimal cannot be cast to class java.nio.ByteBuffer

This is because the schema has a bytes field annotated with the decimal logical type, but the POJO is generated via maven avro plugin with enableDecimalLogicalType = false (the default) and so the receiving instance field type java.nio.ByteBuffer is miss-matched.

This logic is responsible for attaching conversions based on schema logical type annotations; a possible fix would involve interrogating the receiving instance via reflection for receiving field type and matching this with what's returned from Conversion.getConvertedType() or simply an informational/documentation fix stating that schema logical type annotations have to be accompanied by enableDecimalLogicalType = true setting in the avro compiler.

@kevinburkesegment kevinburkesegment changed the title AVRO-XXXX: FastReaderBuilder throws ClassCastException for schemas with java-class attribute AVRO-4225: FastReaderBuilder throws ClassCastException for schemas with java-class attribute Jan 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Java Pull Requests for Java binding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants