santosh-d3vpl3x opened a new pull request, #3715:
URL: https://github.com/apache/avro/pull/3715

   ## What is the purpose of the change
   
   Fixes AVRO-4225: 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`.
   
   ## The Fix
   
   Explicitly handle both `Utf8` and `String` types, consistent with the rest 
of the Avro codebase:
   
   ```java
   Object value = stringReader.read(null, decoder);
   String stringValue = value instanceof Utf8 ? ((Utf8) value).toString() : 
(String) value;
   return transformer.apply(stringValue);
   ```
   
   ## Verifying this change
   
   Added test class `FastReaderBuilderJavaClassTest` with two test cases:
   - `genericDatumReaderWithJavaClassAttribute` - tests union type with 
java-class
   - `genericDatumReaderWithDirectJavaClassString` - tests direct string field 
with java-class
   
   Both tests fail without the fix (ClassCastException) and pass with the fix.
   
   ## Documentation
   
   - Does this pull request introduce a new feature? No
   - If yes, how is the feature documented? N/A


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to