Skip to content
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

ProxySelector.setDefault(null); will causes failure in other maven goal's httpclient creation. #23

Closed
peidong-hu opened this issue Feb 2, 2015 · 0 comments
Labels

Comments

@peidong-hu
Copy link

The following code in selenium-standalone-server-plugin/src/main/java/com/lazerycode/selenium/download/DetectProxyConfig.java

causes failed httpclient creation when running another program in maven with your plugin. Errors will be like, (the reason is the default proxyselector has been set to null by your plugin.)

Caused by: java.lang.NullPointerException
at org.apache.http.impl.conn.SystemDefaultRoutePlanner.determineProxy(SystemDefaultRoutePlanner.java:79)
at org.apache.http.impl.conn.DefaultRoutePlanner.determineRoute(DefaultRoutePlanner.java:73)
at org.apache.http.impl.client.InternalHttpClient.determineRoute(InternalHttpClient.java:126)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
at org.openqa.selenium.remote.HttpCommandExecutor.fallBackExecute(HttpCommandExecutor.java:215)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:184)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.execute(NewProfileExtensionConnection.java:165)
at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.execute(FirefoxDriver.java:362)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:572)
... 63 more
===================error code piece======================
private Proxy getProxy() {
List proxyList = null;
try {
ProxySelector defaultProxy = ProxySelector.getDefault();
proxyList = defaultProxy.select(new URI("http://foo.bar"));
ProxySelector.setDefault(null); //<-----this will globally set the default ProxySelector to null which causes the other program in maven to fail when creating httpclient. In a sense of real-world use case, DefaultProxySelector should never be reset after system initialization. probably java should declare this variable to final type.
} catch (Exception ignored) {
}
if (null != proxyList) {
for (Proxy proxy : proxyList) {
if (null != proxy) {
return proxy;
}
}
}
return null;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants