diff --git a/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java b/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java index 970260fcb..cf0334e81 100644 --- a/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java +++ b/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java @@ -66,7 +66,6 @@ import org.apache.http.params.HttpParamsNames; import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.HttpContext; import org.apache.http.util.Args; -import org.apache.http.util.Asserts; /** * Internal class. @@ -122,7 +121,6 @@ class InternalHttpClient extends CloseableHttpClient { if (host == null) { host = (HttpHost) request.getParams().getParameter(ClientPNames.DEFAULT_HOST); } - Asserts.notNull(host, "Target host"); return this.routePlanner.determineRoute(host, request, context); } diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/DefaultRoutePlanner.java b/httpclient/src/main/java/org/apache/http/impl/conn/DefaultRoutePlanner.java index 0dce040b0..b56d2f8ed 100644 --- a/httpclient/src/main/java/org/apache/http/impl/conn/DefaultRoutePlanner.java +++ b/httpclient/src/main/java/org/apache/http/impl/conn/DefaultRoutePlanner.java @@ -32,6 +32,7 @@ import java.net.InetAddress; import org.apache.http.HttpException; import org.apache.http.HttpHost; import org.apache.http.HttpRequest; +import org.apache.http.ProtocolException; import org.apache.http.annotation.Immutable; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.protocol.HttpClientContext; @@ -64,8 +65,10 @@ public class DefaultRoutePlanner implements HttpRoutePlanner { final HttpHost host, final HttpRequest request, final HttpContext context) throws HttpException { - Args.notNull(host, "Target host"); Args.notNull(request, "Request"); + if (host == null) { + throw new ProtocolException("Target host is not specified"); + } final HttpClientContext clientContext = HttpClientContext.adapt(context); final RequestConfig config = clientContext.getRequestConfig(); final InetAddress local = config.getLocalAddress(); diff --git a/httpclient/src/test/java/org/apache/http/impl/conn/TestDefaultRoutePlanner.java b/httpclient/src/test/java/org/apache/http/impl/conn/TestDefaultRoutePlanner.java index 20988fc54..611d0e721 100644 --- a/httpclient/src/test/java/org/apache/http/impl/conn/TestDefaultRoutePlanner.java +++ b/httpclient/src/test/java/org/apache/http/impl/conn/TestDefaultRoutePlanner.java @@ -30,6 +30,7 @@ package org.apache.http.impl.conn; import org.apache.http.HttpHost; import org.apache.http.HttpRequest; import org.apache.http.HttpVersion; +import org.apache.http.ProtocolException; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.protocol.HttpClientContext; import org.apache.http.conn.SchemePortResolver; @@ -102,4 +103,12 @@ public class TestDefaultRoutePlanner { Mockito.verify(schemePortResolver, Mockito.never()).resolve(Mockito.any()); } + @Test(expected= ProtocolException.class) + public void testNullTarget() throws Exception { + final HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1); + + final HttpContext context = new BasicHttpContext(); + routePlanner.determineRoute(null, request, context); + } + }