Skip to content

Commit a6e6f5b

Browse files
committed
Resolve sonar issues upon scanning
1 parent b5f71a0 commit a6e6f5b

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,17 +207,16 @@ private String resolveHost(String host) {
207207
}
208208

209209
private int resolvePort(int port) {
210-
return port == 0 && useSystemPropertyValues ?
211-
ProxySystemSetting.PROXY_PORT.getStringValue().map(Integer::parseInt).orElse(0)
212-
: port;
210+
return port == 0 && Boolean.TRUE.equals(useSystemPropertyValues) ?
211+
ProxySystemSetting.PROXY_PORT.getStringValue().map(Integer::parseInt).orElse(0) : port;
213212
}
214213

215214
/**
216215
* Uses the configuration options, system setting property and returns the final value of the given member.
217216
*/
218217
private String resolveValue(String value, ProxySystemSetting systemSetting) {
219-
return value == null && useSystemPropertyValues ? systemSetting.getStringValue().orElse(null)
220-
: value;
218+
return value == null && Boolean.TRUE.equals(useSystemPropertyValues) ?
219+
systemSetting.getStringValue().orElse(null) : value;
221220
}
222221

223222
private static final class BuilderImpl implements Builder {

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.util.stream.Collectors;
2323
import software.amazon.awssdk.annotations.SdkPublicApi;
2424
import software.amazon.awssdk.utils.ProxySystemSetting;
25-
import software.amazon.awssdk.utils.StringUtils;
2625
import software.amazon.awssdk.utils.builder.CopyableBuilder;
2726
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
2827

@@ -231,24 +230,23 @@ private String resolveHost(String host) {
231230
}
232231

233232
private int resolvePort(int port) {
234-
return port == 0 && useSystemPropertyValues ?
235-
ProxySystemSetting.PROXY_PORT.getStringValue().map(Integer::parseInt).orElse(0)
236-
: port;
233+
return port == 0 && Boolean.TRUE.equals(useSystemPropertyValues) ?
234+
ProxySystemSetting.PROXY_PORT.getStringValue().map(Integer::parseInt).orElse(0) : port;
237235
}
238236

239237
/**
240238
* Uses the configuration options, system setting property and returns the final value of the given member.
241239
*/
242240
private String resolveValue(String value, ProxySystemSetting systemSetting) {
243-
return value == null && useSystemPropertyValues ? systemSetting.getStringValue().orElse(null)
244-
: value;
241+
return value == null && Boolean.TRUE.equals(useSystemPropertyValues) ?
242+
systemSetting.getStringValue().orElse(null) : value;
245243
}
246244

247245
private Set<String> parseNonProxyHostsProperty() {
248-
String nonProxyHosts = ProxySystemSetting.NON_PROXY_HOSTS.getStringValue().orElse(null);
246+
String nonProxyHostsSystem = ProxySystemSetting.NON_PROXY_HOSTS.getStringValue().orElse(null);
249247

250-
if (!StringUtils.isEmpty(nonProxyHosts)) {
251-
return Arrays.stream(nonProxyHosts.split("\\|"))
248+
if (nonProxyHostsSystem != null && !nonProxyHostsSystem.isEmpty()) {
249+
return Arrays.stream(nonProxyHostsSystem.split("\\|"))
252250
.map(String::toLowerCase)
253251
.map(s -> s.replace("*", ".*?"))
254252
.collect(Collectors.toSet());

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class ProxyConfigurationTest {
3434
private static final Random RNG = new Random();
3535
private static final String TEST_HOST = "foo.com";
3636
private static final int TEST_PORT = 7777;
37+
private static final String TEST_NON_PROXY_HOST = "bar.com";
3738
private static final String TEST_USER = "testuser";
3839
private static final String TEST_PASSWORD = "123";
3940

@@ -55,10 +56,13 @@ public void build_setsAllProperties() {
5556
@Test
5657
public void build_systemPropertyDefault() {
5758
setProxyProperties();
59+
Set<String> nonProxyHost = new HashSet<>();
60+
nonProxyHost.add("bar.com");
5861
ProxyConfiguration config = ProxyConfiguration.builder().build();
5962

6063
assertThat(config.host()).isEqualTo(TEST_HOST);
6164
assertThat(config.port()).isEqualTo(TEST_PORT);
65+
assertThat(config.nonProxyHosts()).isEqualTo(nonProxyHost);
6266
assertThat(config.username()).isEqualTo(TEST_USER);
6367
assertThat(config.password()).isEqualTo(TEST_PASSWORD);
6468
assertThat(config.scheme()).isNull();
@@ -67,10 +71,13 @@ public void build_systemPropertyDefault() {
6771
@Test
6872
public void build_systemPropertyEnabled() {
6973
setProxyProperties();
74+
Set<String> nonProxyHost = new HashSet<>();
75+
nonProxyHost.add("bar.com");
7076
ProxyConfiguration config = ProxyConfiguration.builder().useSystemPropertyValues(Boolean.TRUE).build();
7177

7278
assertThat(config.host()).isEqualTo(TEST_HOST);
7379
assertThat(config.port()).isEqualTo(TEST_PORT);
80+
assertThat(config.nonProxyHosts()).isEqualTo(nonProxyHost);
7481
assertThat(config.username()).isEqualTo(TEST_USER);
7582
assertThat(config.password()).isEqualTo(TEST_PASSWORD);
7683
assertThat(config.scheme()).isNull();
@@ -79,15 +86,20 @@ public void build_systemPropertyEnabled() {
7986
@Test
8087
public void build_systemPropertyDisabled() {
8188
setProxyProperties();
89+
Set<String> nonProxyHost = new HashSet<>();
90+
nonProxyHost.add("test.com");
91+
8292
ProxyConfiguration config = ProxyConfiguration.builder()
8393
.host("localhost")
8494
.port(8888)
95+
.nonProxyHosts(nonProxyHost)
8596
.username("username")
8697
.password("password")
8798
.useSystemPropertyValues(Boolean.FALSE).build();
8899

89100
assertThat(config.host()).isEqualTo("localhost");
90101
assertThat(config.port()).isEqualTo(8888);
102+
assertThat(config.nonProxyHosts()).isEqualTo(nonProxyHost);
91103
assertThat(config.username()).isEqualTo("username");
92104
assertThat(config.password()).isEqualTo("password");
93105
assertThat(config.scheme()).isNull();
@@ -96,15 +108,20 @@ public void build_systemPropertyDisabled() {
96108
@Test
97109
public void build_systemPropertyOverride() {
98110
setProxyProperties();
111+
Set<String> nonProxyHost = new HashSet<>();
112+
nonProxyHost.add("test.com");
113+
99114
ProxyConfiguration config = ProxyConfiguration.builder()
100115
.host("localhost")
101116
.port(8888)
117+
.nonProxyHosts(nonProxyHost)
102118
.username("username")
103119
.password("password")
104120
.build();
105121

106122
assertThat(config.host()).isEqualTo("localhost");
107123
assertThat(config.port()).isEqualTo(8888);
124+
assertThat(config.nonProxyHosts()).isEqualTo(nonProxyHost);
108125
assertThat(config.username()).isEqualTo("username");
109126
assertThat(config.password()).isEqualTo("password");
110127
assertThat(config.scheme()).isNull();
@@ -210,13 +227,15 @@ private Set<String> randomSet() {
210227
private void setProxyProperties() {
211228
System.setProperty("http.proxyHost", TEST_HOST);
212229
System.setProperty("http.proxyPort", Integer.toString(TEST_PORT));
230+
System.setProperty("http.nonProxyHosts", TEST_NON_PROXY_HOST);
213231
System.setProperty("http.proxyUser", TEST_USER);
214232
System.setProperty("http.proxyPassword", TEST_PASSWORD);
215233
}
216234

217235
private static void clearProxyProperties() {
218236
System.clearProperty("http.proxyHost");
219237
System.clearProperty("http.proxyPort");
238+
System.clearProperty("http.nonProxyHosts");
220239
System.clearProperty("http.proxyUser");
221240
System.clearProperty("http.proxyPassword");
222241
}

0 commit comments

Comments
 (0)