Skip to content

AVRO-4189: [Java] Use ClassUtils.forName() in FastReaderBuilder for consistency#3693

Merged
iemejia merged 1 commit intoapache:mainfrom
iemejia:fix/fastreaderbuilder-use-classutils-forname
Mar 31, 2026
Merged

AVRO-4189: [Java] Use ClassUtils.forName() in FastReaderBuilder for consistency#3693
iemejia merged 1 commit intoapache:mainfrom
iemejia:fix/fastreaderbuilder-use-classutils-forname

Conversation

@iemejia
Copy link
Copy Markdown
Member

@iemejia iemejia commented Mar 19, 2026

I noticed that FastReaderBuilder.findClass() was using data.getClassLoader().loadClass() directly, bypassing ClassUtils.forName() which is used everywhere else in the codebase. This change aligns FastReaderBuilder with the standard class loading path and adds tests for class loading behavior.

What is the purpose of the change

(For example: This pull request improves file read performance by buffering data, fixing AVRO-XXXX.)

Verifying this change

(Please pick one of the following options)

This change is a trivial rework / code cleanup without any test coverage.

(or)

This change is already covered by existing tests, such as (please describe tests).

(or)

This change added tests and can be verified as follows:

(example:)

  • Extended interop tests to verify consistent valid schema names between SDKs
  • Added test that validates that Java throws an AvroRuntimeException on invalid binary data
  • Manually verified the change by building the website and checking the new redirect

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 Mar 19, 2026
Copy link
Copy Markdown
Contributor

@gszadovszky gszadovszky left a comment

Choose a reason for hiding this comment

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

Thanks a lot for working on this, @iemejia.

return Optional.of(data.getClassLoader().loadClass(clazz));
} catch (ReflectiveOperationException e) {
return Optional.of(ClassUtils.forName(data.getClassLoader(), clazz));
} catch (ClassNotFoundException | SecurityException e) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm wondering if it is a good practice here to swallow the SecurityException. It will be hard to analyze why the class loading is not working while the SecurityException contains a comprehensive explanation. WDYT?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh you have a point I somehow did not remember that SecurityException was a RuntimeException. I will fix it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done @gszadovszky PTAL again, thx

FastReaderBuilder.findClass() was using data.getClassLoader().loadClass()
directly, bypassing ClassUtils.forName() which is used everywhere else in
the codebase. This change aligns FastReaderBuilder with the standard class
loading path and adds tests for class loading behavior.
@iemejia iemejia force-pushed the fix/fastreaderbuilder-use-classutils-forname branch from 87bec1b to a63fb2e Compare March 30, 2026 22:28
@iemejia iemejia merged commit bd916d3 into apache:main Mar 31, 2026
9 checks passed
@iemejia iemejia deleted the fix/fastreaderbuilder-use-classutils-forname branch March 31, 2026 07:52
iemejia added a commit to iemejia/avro that referenced this pull request Apr 1, 2026
…onsistency (apache#3693)

FastReaderBuilder.findClass() was using data.getClassLoader().loadClass()
directly, bypassing ClassUtils.forName() which is used everywhere else in
the codebase. This change aligns FastReaderBuilder with the standard class
loading path and adds tests for class loading behavior.
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