Ardesco / driver-binary-downloader-maven-plugin

A Maven plugin that will download the WebDriver stand alone server executables for use in your mavenised Selenium project.
Apache License 2.0
92 stars 52 forks source link

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

Closed peidong-hu closed 9 years ago

peidong-hu commented 9 years ago

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; }