Skip to content

Commit 6ceac77

Browse files
debora-itoIto
andauthored
Add a null check in ProxyConfiguration to avoid a NullPointerException when calling toBuilder (#2907)
* Add a null check in ProxyConfiguration to avoid a NullPointerException when calling toBuilder Co-authored-by: Ito <[email protected]>
1 parent abe96fd commit 6ceac77

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"category": "AWS SDK for Java v2",
3+
"contributor": "",
4+
"type": "bugfix",
5+
"description": "Add null check for nonProxyHosts in Apache HTTP Client ProxyConfiguration."
6+
}

http-clients/apache-client/src/main/java/software/amazon/awssdk/http/apache/ProxyConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ public void setNtlmWorkstation(String ntlmWorkstation) {
365365

366366
@Override
367367
public Builder nonProxyHosts(Set<String> nonProxyHosts) {
368-
this.nonProxyHosts = new HashSet<>(nonProxyHosts);
368+
this.nonProxyHosts = nonProxyHosts != null ? new HashSet<>(nonProxyHosts) : null;
369369
return this;
370370
}
371371

http-clients/apache-client/src/test/java/software/amazon/awssdk/http/apache/ProxyConfigurationTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,18 @@ public void testProxyConfigurationWithSystemPropertyEnabled() throws Exception {
105105
assertThat(config.username()).isEqualTo("user");
106106
}
107107

108+
@Test
109+
public void testProxyConfigurationWithoutNonProxyHosts_toBuilder_shouldNotThrowNPE() {
110+
ProxyConfiguration proxyConfiguration =
111+
ProxyConfiguration.builder()
112+
.endpoint(URI.create("http://localhost:4321"))
113+
.username("username")
114+
.password("password")
115+
.build();
116+
117+
assertThat(proxyConfiguration.toBuilder()).isNotNull();
118+
}
119+
108120
private static void clearProxyProperties() {
109121
System.clearProperty("http.proxyHost");
110122
System.clearProperty("http.proxyPort");

0 commit comments

Comments
 (0)