Skip to content

Commit 7a61453

Browse files
author
Stephane Landelle
committed
RequestBuilder.setUrl shouldn't accept an URI without a host, close AsyncHttpClient#571
1 parent a1f779f commit 7a61453

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/main/java/com/ning/http/client/RequestBuilderBase.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,10 @@ public T setUrl(String url) {
379379
}
380380

381381
public T setURI(URI uri) {
382+
if (uri.getHost() == null)
383+
throw new NullPointerException("uri.host");
382384
if (uri.getPath() == null)
383-
throw new IllegalArgumentException("Unsupported uri format: " + uri);
385+
throw new NullPointerException("uri.path");
384386
request.originalUri = uri;
385387
addQueryParameters(request.originalUri);
386388
request.uri = null;

src/test/java/com/ning/http/client/async/AsyncProvidersBasicTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -393,14 +393,13 @@ public void onThrowable(Throwable t) {
393393
}
394394
}
395395

396-
@Test(groups = { "online", "default_provider", "async" })
396+
@Test(groups = { "online", "default_provider", "async" }, expectedExceptions = { NullPointerException.class })
397397
public void asyncNullSchemeTest() throws Throwable {
398398
AsyncHttpClient client = getAsyncHttpClient(null);
399399
try {
400400
client.prepareGet("www.sun.com").execute();
401-
Assert.fail();
402-
} catch (IllegalArgumentException ex) {
403-
Assert.assertTrue(true);
401+
} finally {
402+
client.close();;
404403
}
405404
}
406405

@@ -1654,7 +1653,7 @@ protected String getBrokenTargetUrl() {
16541653
return String.format("http:127.0.0.1:%d/foo/test", port1);
16551654
}
16561655

1657-
@Test(groups = { "standalone", "default_provider" }, expectedExceptions = { IllegalArgumentException.class })
1656+
@Test(groups = { "standalone", "default_provider" }, expectedExceptions = { NullPointerException.class })
16581657
public void invalidUri() throws Exception {
16591658
AsyncHttpClient client = getAsyncHttpClient(null);
16601659
try {

0 commit comments

Comments
 (0)