GeezerVison is showing github.com — fix(auth): restore transportFactory upon deserialization in InternalAwsSecurityCredentialsSupplier by lqiu96 · Pull Request #14340 · googleapis/google-cloud-java
Conversation
lqiu96
commented
Sep 9, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Fixes #14050
Part of #12580
In InternalAwsSecurityCredentialsSupplier, transportFactory is marked transient but no transportFactoryClassName was retained and no readObject was defined. Consequently, after Java deserialization (common in distributed frameworks like Apache Flink and Apache Spark), transportFactory is null. When deserialized AwsCredentials attempts to refresh its token, a NullPointerException is thrown when retrieving AWS security credentials or region from the metadata service.
This change:
- Records transportFactoryClassName during construction.
- Implements readObject to restore transportFactory using OAuth2Credentials.newInstance(transportFactoryClassName), with fallback to OAuth2Utils.HTTP_TRANSPORT_FACTORY for backwards compatibility with previously serialized streams.
- Adds reproduction and serialization unit tests verifying credentials and region retrieval after deserialization, including token refresh in AwsCredentials.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
gemini-code-assist[bot] reacted with eyes emoji
There was a problem hiding this comment.
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 implements serialization and deserialization support for the InternalAwsSecurityCredentialsSupplier class by storing and restoring the HttpTransportFactory class name. It also adds unit tests to verify that credentials and region retrieval, as well as token refreshing, work correctly after deserialization. The review feedback highlights a potential compatibility issue where serializing the internal class name of the default fallback transport factory could lead to ClassNotFoundException in future versions if that class is renamed or refactored. It is recommended to set transportFactoryClassName to null when the default factory is used.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…wsSecurityCredentialsSupplier
Fixes #14050
Fixes #1538
In InternalAwsSecurityCredentialsSupplier, transportFactory is marked
transient but no transportFactoryClassName was retained and no readObject
was defined. Consequently, after Java deserialization (common in distributed
frameworks like Apache Flink and Apache Spark), transportFactory is null.
When deserialized AwsCredentials attempts to refresh its token, a
NullPointerException is thrown when retrieving AWS security credentials
or region from the metadata service.
This change:
1. Records transportFactoryClassName during construction.
2. Implements readObject to restore transportFactory using
OAuth2Credentials.newInstance(transportFactoryClassName).
3. Adds reproduction and serialization unit tests verifying credentials
and region retrieval after deserialization, including token refresh in
AwsCredentials.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Sep 22, 2026
Reviewers
whowes
whowes approved these changes
+1 more reviewer
Reviewers whose approvals may not affect merge requirements
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|