JRAW icon indicating copy to clipboard operation
JRAW copied to clipboard

NullPointerException caused by outdated OkHttp

Open omarathon opened this issue 5 years ago • 1 comments

When one creates an OkHttpNetworkAdaptor without specifying their own working OkHttpClient, the default OkHttpClient generated may have a null ProxySelector.

This causes a NullPointerException in my program using JRAW.

I discovered that ProxySelector.getDefault() returns null for Linux machines, so to circumvient the error I created an OkHttpNetworkAdaptor with a custom OkHttpClient, which has a custom ProxySelector which simply doesn't use a proxy (see https://github.com/square/okhttp/pull/4237/files, the NullProxySelector which was added).

OkHttp has been updated to implement such a NullProxySelector. Please update OkHttp, or implement the above change in https://github.com/mattbdean/JRAW/blob/master/lib/src/main/kotlin/net/dean/jraw/http/OkHttpNetworkAdapter.kt, specifically the line private val http: OkHttpClient = OkHttpClient() - you must use the OkHttpClient.Builder class and provide the ProxySelector. Such ProxySelector should either be ProxySelector.getDefault(), however if null, the proposed NullProxySelector.

I'd make a PR but this can simply be resolved by updating OkHttp.

Cheers, omarathon

omarathon avatar Jan 01 '20 09:01 omarathon

Note: this issue was officially raised on the OkHttp GitHub page: https://github.com/square/okhttp/issues/4232

omarathon avatar Jan 01 '20 09:01 omarathon