Skip to content

Improved error messages if an invalid URL was passed #1442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 31, 2017
Merged

Improved error messages if an invalid URL was passed #1442

merged 5 commits into from
Jul 31, 2017

Conversation

bahrmichael
Copy link

    @Test
    public void name() throws Exception {
        AsyncHttpClient asyncHttpClient = sut.getAsyncHttpClient();
        asyncHttpClient.prepareDelete("url");
    }

currently leads to

java.lang.NullPointerException: scheme

	at org.asynchttpclient.util.Assertions.assertNotNull(Assertions.java:23)
	at org.asynchttpclient.uri.Uri.<init>(Uri.java:64)
	at org.asynchttpclient.uri.Uri.create(Uri.java:39)
	at org.asynchttpclient.uri.Uri.create(Uri.java:32)
	at org.asynchttpclient.RequestBuilderBase.setUrl(RequestBuilderBase.java:148)
	at org.asynchttpclient.DefaultAsyncHttpClient.requestBuilder(DefaultAsyncHttpClient.java:259)
	at org.asynchttpclient.DefaultAsyncHttpClient.prepareDelete(DefaultAsyncHttpClient.java:157)

This may be confusing at first, so I changed the value passed from the Uri constructor to assertNotNull to be more descriptive.

@slandelle
Copy link
Contributor

Hi @bahrmichael

Thanks, but I think the current checks are perfectly valid as they currently are and the ones you would like should actually be in the create static method as they are related to the parsing result.

Could you please update your PR?

Thanks!

those new/different messages are not in the right place.
They are related to the parsing, not the constructor, so they should be thrown

@bahrmichael
Copy link
Author

I will.

@slandelle slandelle merged commit 9dc9e28 into AsyncHttpClient:master Jul 31, 2017
@slandelle
Copy link
Contributor

Thanks!

@slandelle slandelle modified the milestones: 2.1.0, 2.0.34 Jul 31, 2017
@bahrmichael
Copy link
Author

Thanks for reacting so fast! First open source PR merged 🎉

@slandelle slandelle mentioned this pull request Jul 31, 2017
slandelle added a commit that referenced this pull request Jul 31, 2017
Motivation:

Following #1442, we shouldn't accept Uri with empty scheme or empty
host, such as "http://".

Modifications:

* Introduce MiscUtils#isEmpty(String)
* Throw IllegalArgumentException on empty scheme or host, with message
mentioning missing field and original url

Result:

Better control on Uri that could cause AHC to choke
@slandelle
Copy link
Contributor

Congrats! Hopefully more will follow and you'll get used to it ;-)

Please note the follow up in #1445

slandelle added a commit that referenced this pull request Jul 31, 2017
Motivation:

Following #1442, we shouldn't accept Uri with empty scheme or empty
host, such as "http://".

Modifications:

* Introduce MiscUtils#isEmpty(String)
* Throw IllegalArgumentException on empty scheme or host, with message
mentioning missing field and original url

Result:

Better control on Uri that could cause AHC to choke
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants