Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
5.0 Beta3
-
None
Description
When a proxy host and port are specified via the JVM properties https.proxyHost / https.proxyPort, an IllegalArgumentException is thrown on any HTTP request (see stacktrace below)
Steps to reproduce
1) Specify a proxy via https.proxyHost/https.proxyPort JVM properties
2) Execute for example a HTTP GET via httpClient.execute(...)
3) java.lang.IllegalArgumentException: Inet address must not be null is thrown (see stacktrace below)
Analysis
The sun.net.spi.DefaultProxySelector deliberately does not resolve the proxy's address, see http://hg.openjdk.java.net/jdk10/jdk10/jdk/file/9b8c96f96a0f/src/share/classes/sun/net/spi/DefaultProxySelector.java#l294.
SystemDefaultRoutePlanner in httpclient5 assumes the address has been resolved, see https://github.com/apache/httpcomponents-client/blob/5.0-beta3/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/SystemDefaultRoutePlanner.java#L100
See the attached reproducer test or the code snippet below.
Versions used
org.apache.httpcomponents.client5:httpclient5:5.0-beta3
Oracle JDK 10.0.2 on OSX and Windows
java.lang.IllegalArgumentException: Inet address must not be null
at org.apache.hc.core5.util.Args.illegalArgumentExceptionNotNull(Args.java:101)
at org.apache.hc.core5.util.Args.notNull(Args.java:150)
at org.apache.hc.core5.http.HttpHost.<init>(HttpHost.java:286)
at org.apache.hc.client5.http.impl.routing.SystemDefaultRoutePlanner.determineProxy(SystemDefaultRoutePlanner.java:100)
at org.apache.hc.client5.http.impl.routing.DefaultRoutePlanner.determineRoute(DefaultRoutePlanner.java:71)
at org.apache.hc.client5.http.impl.classic.InternalHttpClient.determineRoute(InternalHttpClient.java:122)
at org.apache.hc.client5.http.impl.classic.InternalHttpClient.doExecute(InternalHttpClient.java:166)
at org.apache.hc.client5.http.impl.classic.CloseableHttpClient.execute(CloseableHttpClient.java:77)
at org.apache.hc.client5.http.impl.classic.CloseableHttpClient.execute(CloseableHttpClient.java:102)
System.setProperty("https.proxyHost", "<TODO: Your Proxy Host Here>"); System.setProperty("https.proxyPort", "8080"); CloseableHttpClient httpClient = HttpClients.createSystem(); HttpGet httpGet = new HttpGet("https://www.google.com/"); CloseableHttpResponse response = httpClient.execute(httpGet); System.out.println(response.getCode());