Skip to content

GH-3897: Replace deprecated Class.newInstance() - #3903

Open
Fokko wants to merge 1 commit into
apache:masterfrom
Fokko:jdk17-replace-class-newinstance
Open

Fokko wants to merge 1 commit into
apache:masterfrom
Fokko:jdk17-replace-class-newinstance

Conversation

@Fokko

@Fokko Fokko commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Rationale for this change

Class.newInstance() has been deprecated since Java 9.

What changes are included in this PR?

Replace it with getDeclaredConstructor().newInstance() in parquet-hadoop (ParquetInputFormat, ParquetOutputFormat, the crypto factories, KeyToolkit), parquet-thrift, parquet-column (Operators) and parquet-format-structures. The catch clauses are widened to ReflectiveOperationException, keeping the existing wrapping exceptions and messages.

Are these changes tested?

Covered by the existing tests of the touched modules.

Are there any user-facing changes?

A constructor that throws a checked exception is now reported wrapped (through the existing BadConfigurationException / RuntimeException wrappers) instead of being sneaky-thrown by Class.newInstance().

Closes #3897

This pull request and its description were written by Isaac.

Class.newInstance() has been deprecated since Java 9. Use
getDeclaredConstructor().newInstance() instead and widen the catch
clauses to ReflectiveOperationException, keeping the existing wrapping
exceptions and messages. As a result, checked exceptions thrown by a
constructor now arrive wrapped in an InvocationTargetException instead
of being sneaky-thrown.

Co-authored-by: Isaac <no-reply@databricks.com>
@Fokko
Fokko requested a review from wgtmac October 28, 2026 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace deprecated Class.newInstance()

1 participant