Skip to content

Add a null check in ProxyConfiguration to avoid a NullPointerException when calling toBuilder #2907

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 23, 2021

Conversation

debora-ito
Copy link
Member

Motivation and Context

Fixes #2884

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have read the README document
  • I have added tests to cover my changes
  • All new and existing tests passed
  • A short description of the change has been added to the CHANGELOG
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

@debora-ito debora-ito requested a review from a team as a code owner December 9, 2021 22:39
if (nonProxyHosts != null) {
this.nonProxyHosts = new HashSet<>(nonProxyHosts);
} else {
this.nonProxyHosts = Collections.emptySet();
Copy link
Contributor

Choose a reason for hiding this comment

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

If we force the Null Value to be assigned as Empty set then it might break the below code

/**
* The hosts that the client is allowed to access without going through the proxy.
*
* If the value is not set on the object, the value represent by "http.nonProxyHosts" system property is returned.
* If system property is also not set, an unmodifiable empty set is returned.
*
* @see Builder#nonProxyHosts(Set)
*/
public Set<String> nonProxyHosts() {
Set<String> hosts = nonProxyHosts == null && useSystemPropertyValues ? parseNonProxyHostsProperty()
: nonProxyHosts;
return Collections.unmodifiableSet(hosts != null ? hosts : Collections.emptySet());
}

Here we do a null check on nonProxyHosts , if user set the value of nonProxyHosts as null internally we changing it to Collections.emptySet() might affect the getter public Set<String> nonProxyHosts()

Why don't we just do something s below

        @Override
        public Builder nonProxyHosts(Set<String> nonProxyHosts) {
            this.nonProxyHosts = nonProxyHosts != null ? new HashSet<>(nonProxyHosts) : null;
            return this;
        }

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@debora-ito debora-ito merged commit 6ceac77 into aws:master Dec 23, 2021
aws-sdk-java-automation added a commit that referenced this pull request Feb 23, 2024
…08d78b610

Pull request: release <- staging/d13c4c80-18cd-4379-9d90-a1708d78b610
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.

ProxyConfiguration.toBuilder throws NullPointerException
2 participants