AVRO-4321: Fix NPE on getConversionByClass - #3908
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a NullPointerException in the Java Avro data model when callers ask for a conversion by datum class but provide a null LogicalType, which can happen for classes that have conversions registered by default (e.g., BigDecimal) even when no logical type is available.
Changes:
- Add a null guard in
GenericData#getConversionByClass(Class, LogicalType)to returnnullinstead of dereferencinglogicalType. - Add a JUnit test covering the
nulllogical type case viaReflectData.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java | Prevents NPE by returning null when logicalType is null in conversion lookup. |
| lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflectData.java | Adds regression test ensuring getConversionByClass(..., null) returns null (no NPE). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
Author
|
Cherry-picked to branch-1.12. |
RyanSkraba
added a commit
that referenced
this pull request
Aug 5, 2026
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.
What is the purpose of the change
Fix the NPE caused by AVRO-3989 on classes that have a datum with a Conversion but not a LogicalType.
Verifying this change
This change added tests
getConversionByClassWithNullLogicalTypeReturnsNullDocumentation