Skip to content

AVRO-4321: Fix NPE on getConversionByClass - #3908

Merged
RyanSkraba merged 1 commit into
apache:mainfrom
RyanSkraba:ryanskraba/AVRO-4321-npe
Aug 5, 2026
Merged

AVRO-4321: Fix NPE on getConversionByClass#3908
RyanSkraba merged 1 commit into
apache:mainfrom
RyanSkraba:ryanskraba/AVRO-4321-npe

Conversation

@RyanSkraba

Copy link
Copy Markdown
Contributor

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 getConversionByClassWithNullLogicalTypeReturnsNull

Documentation

  • Does this pull request introduce a new feature? (yes / no)
  • If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)

@github-actions github-actions Bot added the Java Pull Requests for Java binding label Aug 2, 2026
@RyanSkraba
RyanSkraba requested a lite review from Copilot August 4, 2026 16:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 return null instead of dereferencing logicalType.
  • Add a JUnit test covering the null logical type case via ReflectData.

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.

@RyanSkraba
RyanSkraba merged commit cb1ebc2 into apache:main Aug 5, 2026
9 checks passed
@RyanSkraba
RyanSkraba deleted the ryanskraba/AVRO-4321-npe branch August 5, 2026 09:23
@RyanSkraba

Copy link
Copy Markdown
Contributor Author

Cherry-picked to branch-1.12.

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