Skip to content

Commit 56e9723

Browse files
committed
Fix #68 don't try to convert a null to an Integer.
1 parent ca94401 commit 56e9723

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/main/java/com/lazerycode/selenium/download/DetectProxyConfig.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.lazerycode.selenium.download;
22

33
import com.google.common.base.Strings;
4+
import org.apache.log4j.Logger;
45

56
import java.net.InetSocketAddress;
67
import java.net.Proxy;
@@ -10,6 +11,7 @@
1011

1112
public class DetectProxyConfig {
1213

14+
private static final Logger LOG = Logger.getLogger(DetectProxyConfig.class);
1315
private static String host;
1416
private static int port;
1517
private static boolean proxyAvailable = false;
@@ -30,7 +32,12 @@ public DetectProxyConfig() {
3032

3133
String proxyHost = System.getProperty("http.proxyHost", System.getenv("http.proxyHost"));
3234
String proxyPortFromSystem = System.getProperty("http.proxyPort", System.getenv("http.proxyPort"));
33-
Integer proxyPort = Integer.valueOf(proxyPortFromSystem);
35+
Integer proxyPort = null;
36+
try {
37+
proxyPort = Integer.valueOf(proxyPortFromSystem);
38+
} catch (NumberFormatException ignored) {
39+
LOG.debug("Invalid proxy port of '" + proxyPortFromSystem + "' found, ignoring...");
40+
}
3441

3542
if (Strings.isNullOrEmpty(proxyHost) || null == proxyPort) {
3643

src/test/java/com/lazerycode/selenium/download/DetectProxyConfigTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public void proxySettingsUsedIfTheyAreSet() {
2929
System.setProperty("http.proxyPort", "" + port);
3030

3131
DetectProxyConfig proxyConfig = new DetectProxyConfig();
32+
3233
assertThat(proxyConfig.getHost(), is(equalTo(host)));
3334
assertThat(proxyConfig.getPort(), is(equalTo(port)));
3435
assertThat(proxyConfig.isProxyAvailable(), is(equalTo(true)));
@@ -40,6 +41,7 @@ public void proxySettingsUsesEnvVariablesIfTheyAreSet() throws Exception {
4041
envVars.set("http.proxyPort", Integer.toString(envPort));
4142

4243
DetectProxyConfig proxyConfig = new DetectProxyConfig();
44+
4345
assertThat(proxyConfig.getHost(), is(equalTo(envHost)));
4446
assertThat(proxyConfig.getPort(), is(equalTo(envPort)));
4547
assertThat(proxyConfig.isProxyAvailable(), is(equalTo(true)));
@@ -55,9 +57,16 @@ public void propertyOverridesEnvVariable() throws Exception {
5557
envVars.set("http.proxyPort", Integer.toString(envPort));
5658

5759
DetectProxyConfig proxyConfig = new DetectProxyConfig();
60+
5861
assertThat(proxyConfig.getHost(), is(equalTo(propHost)));
5962
assertThat(proxyConfig.getPort(), is(equalTo(propPort)));
6063
assertThat(proxyConfig.isProxyAvailable(), is(equalTo(true)));
6164
}
6265

66+
@Test
67+
public void nullProxyHostOrProxyPort() throws Exception {
68+
DetectProxyConfig proxyConfig = new DetectProxyConfig();
69+
70+
assertThat(proxyConfig.isProxyAvailable(), is(equalTo(false)));
71+
}
6372
}

0 commit comments

Comments
 (0)