Skip to content
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

Retrofit module: http client supplier is not invoked, resulting in NPE #1616

Closed
bfg opened this issue Feb 27, 2019 · 1 comment · Fixed by #1617
Closed

Retrofit module: http client supplier is not invoked, resulting in NPE #1616

bfg opened this issue Feb 27, 2019 · 1 comment · Fixed by #1617

Comments

@bfg
Copy link
Contributor

bfg commented Feb 27, 2019

PR #1615 introduced Supplier<AsyncHttpClient> to retrieve HTTP client instance to execute HTTP request, but it's never called because getHttpClient() is not invoked at Call creation procedure. This results in NPE if concrete AsyncHttpClient instance is not set.

java.lang.NullPointerException: httpClient
        at org.asynchttpclient.extras.retrofit.AsyncHttpClientCall.<init>(AsyncHttpClientCall.java:39)
        at org.asynchttpclient.extras.retrofit.AsyncHttpClientCall$AsyncHttpClientCallBuilder.build(AsyncHttpClientCall.java:39)
        at org.asynchttpclient.extras.retrofit.AsyncHttpClientCallFactory.newCall(AsyncHttpClientCallFactory.java:63)
        at com.example.retrofit.CallFactoryRegistry.lambda$getComposite$0(CallFactoryRegistry.java:32)
        at retrofit2.OkHttpCall.createRawCall(OkHttpCall.java:190)
        at retrofit2.OkHttpCall.enqueue(OkHttpCall.java:100)
        at retrofit2.adapter.rxjava.CallEnqueueOnSubscribe.call(CallEnqueueOnSubscribe.java:39)
        at retrofit2.adapter.rxjava.CallEnqueueOnSubscribe.call(CallEnqueueOnSubscribe.java:25)
        at retrofit2.adapter.rxjava.BodyOnSubscribe.call(BodyOnSubscribe.java:36)
        at retrofit2.adapter.rxjava.BodyOnSubscribe.call(BodyOnSubscribe.java:28)

I'll submit PR.

@slandelle
Copy link
Contributor

Please do!

slandelle pushed a commit that referenced this issue Feb 28, 2019
* Lombok update to 1.18.6

* Fixed NPE when http client supplier was specied and http client was not.

This patch addresses issue that resulted in NPE if http client supplier
was specified in `Call.Factory` builder and concrete http client was not,
because `getHttpClient()` method was not invoked while constructing
retrofit `Call` instance.

New, obviously less error prone approach is that http client supplier
gets constructed behind the scenes even if user specifies concrete http
client instance at call factory creation time and http client supplier
is being used exclusively also by `Call` instance. This way there are no
hard references to http client instance dangling around in case some
component creates a `Call` instance and never issues `newCall()` on it.

Fixes #1616.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants