[fix][client] Apply Avro logical type conversions when decoding schema without classloader - #25759
Merged
Merged
Conversation
…a without classloader ### Motivation `AvroReader` only registered logical-type conversions (UUID, decimal, date/time, timestamp) when a non-null `ClassLoader` was supplied, while `AvroWriter` always registers them. This asymmetry caused decoding to fail for any logical-type field when a schema was constructed via `SchemaDefinition.builder().withJsonDef(...)`, where no pojo class or classloader is provided. For example, a `UUID` field encoded with `Schema.AVRO(class)` could not be decoded with `Schema.AVRO(SchemaDefinition.builder().withJsonDef(...))` and failed with: ``` java.lang.IllegalArgumentException: Can not set java.util.UUID field ... to java.lang.String ``` because the `UUIDConversion` was never registered on the reader's `ReflectData`. ### Modifications - `AvroReader` now always builds a fresh `ReflectData` (using the supplied classloader when present, otherwise the default) and calls `AvroSchema.addLogicalTypeConversions(...)` on it, mirroring `AvroWriter`'s behavior. - Added `testDecodeUuidLogicalTypeWithClass` and `testDecodeUuidLogicalTypeWithJsonDef` in `AvroSchemaTest` to cover the UUID logical-type round-trip for both schema construction paths. ### Verifying this change This change added tests and can be verified as follows: - The new `AvroSchemaTest#testDecodeUuidLogicalTypeWithJsonDef` reproduces the original failure and now passes with the fix. - Existing `pulsar-client` schema tests continue to pass. ### Does this pull request potentially affect one of the following parts: - [ ] Dependencies (add or upgrade a dependency) - [ ] The public API - [ ] The schema - [ ] The default values of configurations - [ ] The threading model - [ ] The binary protocol - [ ] The REST endpoints - [ ] The admin CLI options - [ ] The metrics - [ ] Anything that affects deployment
nodece
approved these changes
May 13, 2026
nodece
pushed a commit
to ascentstream/pulsar
that referenced
this pull request
May 19, 2026
…a without classloader (apache#25759) (cherry picked from commit 30ca23f)
nodece
pushed a commit
to ascentstream/pulsar
that referenced
this pull request
May 27, 2026
…a without classloader (apache#25759) (cherry picked from commit 30ca23f)
manas-ctds
pushed a commit
to datastax/pulsar
that referenced
this pull request
Jun 1, 2026
…a without classloader (apache#25759) (cherry picked from commit 30ca23f) (cherry picked from commit f4ef184)
priyanshu-ctds
pushed a commit
to datastax/pulsar
that referenced
this pull request
Jun 9, 2026
…a without classloader (apache#25759) (cherry picked from commit 30ca23f) (cherry picked from commit e7c3731)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
AvroReaderonly registered logical-type conversions (UUID, decimal,date/time, timestamp) when a non-null
ClassLoaderwas supplied, whileAvroWriteralways registers them. This asymmetry caused decoding tofail for any logical-type field when a schema was constructed via
SchemaDefinition.builder().withJsonDef(...), where no pojo class orclassloader is provided.
For example, a
UUIDfield encoded withSchema.AVRO(class)could notbe decoded with
Schema.AVRO(SchemaDefinition.builder().withJsonDef(...))and failed with:
because the
UUIDConversionwas never registered on the reader'sReflectData.Modifications
AvroReadernow always builds a freshReflectData(using thesupplied classloader when present, otherwise the default) and calls
AvroSchema.addLogicalTypeConversions(...)on it, mirroringAvroWriter's behavior.testDecodeUuidLogicalTypeWithClassandtestDecodeUuidLogicalTypeWithJsonDefinAvroSchemaTestto coverthe UUID logical-type round-trip for both schema construction paths.
Verifying this change
This change added tests and can be verified as follows:
AvroSchemaTest#testDecodeUuidLogicalTypeWithJsonDefreproduces the original failure and now passes with the fix.
pulsar-clientschema tests continue to pass.Does this pull request potentially affect one of the following parts: