Skip to content

Commit 0ef53c5

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

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

api/src/main/java/org/asynchttpclient/RequestBuilderBase.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,11 @@ public T setUrl(String url) {
388388
}
389389

390390
public T setURI(URI uri) {
391+
if (uri.getHost() == null)
392+
throw new NullPointerException("uri.host");
391393
if (uri.getPath() == null)
392-
throw new IllegalArgumentException("Unsupported uri format: " + uri);
394+
throw new NullPointerException("uri.path");
395+
393396
request.originalUri = uri;
394397
addQueryParameters(request.originalUri);
395398
request.uri = null;

api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -386,15 +386,12 @@ public void onThrowable(Throwable t) {
386386
}
387387
}
388388

389-
@Test(groups = { "online", "default_provider", "async" })
389+
@Test(groups = { "online", "default_provider", "async" }, expectedExceptions = { NullPointerException.class })
390390
public void asyncNullSchemeTest() throws Exception {
391391
AsyncHttpClient client = getAsyncHttpClient(null);
392392

393393
try {
394394
client.prepareGet("www.sun.com").execute();
395-
fail();
396-
} catch (IllegalArgumentException ex) {
397-
assertTrue(true);
398395
} finally {
399396
client.close();
400397
}
@@ -1555,7 +1552,7 @@ public void getShouldAllowBody() throws IllegalArgumentException, IOException {
15551552
}
15561553
}
15571554

1558-
@Test(groups = { "standalone", "default_provider" }, expectedExceptions = { IllegalArgumentException.class })
1555+
@Test(groups = { "standalone", "default_provider" }, expectedExceptions = { NullPointerException.class })
15591556
public void invalidUri() throws Exception {
15601557
AsyncHttpClient client = getAsyncHttpClient(null);
15611558
try {

0 commit comments

Comments
 (0)