Skip to content

Replace deprecated Class.newInstance()#3312

Open
SethSmucker wants to merge 12 commits intointegrationfrom
task/replace-deprecated-class-newinstance
Open

Replace deprecated Class.newInstance()#3312
SethSmucker wants to merge 12 commits intointegrationfrom
task/replace-deprecated-class-newinstance

Conversation

@SethSmucker
Copy link
Collaborator

Summary

  • Replace deprecated Class.newInstance() with getDeclaredConstructor().newInstance()
  • Update exception handling to use ReflectiveOperationException (covers the additional exceptions from the new API)

Files Changed

  • DatawaveMetricsConfig.java
  • ProtostuffHttpMessageConverter.java

Fixes #3311
Part of #2443

🤖 Generated with Claude Code

…newInstance()

Class.newInstance() has been deprecated since Java 9 because it
propagates exceptions thrown by the nullary constructor, including
checked exceptions. The replacement getDeclaredConstructor().newInstance()
wraps such exceptions in an InvocationTargetException.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@foster33
Copy link
Collaborator

foster33 commented Dec 18, 2025

There are additional occurrences of Class.newInstance() throughout the entire code base outside of just spring-boot-starter-datawave. Those should probably be added as well

SethSmucker and others added 4 commits December 18, 2025 18:45
- QueryIterator.java: c.newInstance() -> c.getDeclaredConstructor().newInstance()
- AggregatingReducer.java: clazz.newInstance() -> clazz.getDeclaredConstructor().newInstance()
- Updated exception handling in related methods and overrides
Copy link
Collaborator

@foster33 foster33 left a comment

Choose a reason for hiding this comment

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

There seems to be 4 more uses of Class.newInstance(). I will go ahead and make those changes.

foster33
foster33 previously approved these changes Jan 15, 2026
@lbschanno
Copy link
Collaborator

One additional usage that needs to be replaced:

  • BulkIngestKeyAggregatingReducer (line 66)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace deprecated Class.newInstance()

4 participants

Comments