Skip to content

fix(core): validate deserialized class types in ServiceOptions.newInstance - #15182

Open
whowes wants to merge 1 commit into
mainfrom
whowes/service-options-reflect
Open

whowes wants to merge 1 commit into
mainfrom
whowes/service-options-reflect

Conversation

@whowes

@whowes whowes commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Hardens ServiceOptions.newInstance by deferring class initialization until assignability to the expected factory interface is verified. Updates ServiceOptions, GrpcTransportOptions, and HttpTransportOptions readObject call sites accordingly and adds unit tests.

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request enhances security and type safety during deserialization by verifying that dynamically instantiated classes are assignable to expected types before they are initialized. It updates ServiceOptions.newInstance to accept an expected class type, avoids running static initializers prematurely, and replaces deprecated reflection calls. Corresponding serialization round-trip tests are added across transport options. The reviewer suggested improving type safety in ServiceOptions.newInstance by changing the expected parameter type from Class<?> to Class, which allows using expected.cast(...) and removing the @SuppressWarnings("unchecked") annotation.

@whowes
whowes force-pushed the whowes/service-options-reflect branch from add5f1a to 8aed79e Compare November 24, 2026 01:41
@whowes
whowes marked this pull request as ready for review November 24, 2026 01:45
@whowes
whowes requested a review from a team as a code owner November 24, 2026 01:45
@whowes
whowes requested a review from lqiu96 November 24, 2026 01:45
@sonarqubecloud

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed for 'gapic-generator-java-root'

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

This branch has not been deployed

No deployments
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.

1 participant