okhttp
okhttp copied to clipboard
Avoid NPEs in JavaNetAuthenticator
Configuring JavaNetAuthenticator as the proxyAuthenticator when using the default ProxySelector causes NPEs to be thrown because the socket addresses returned are unresolved:
Exception in thread "main" java.lang.NullPointerException: address() as InetSocketAddress).address must not be null
at okhttp3.internal.authenticator.JavaNetAuthenticator.connectToInetAddress(JavaNetAuthenticator.kt:91)
at okhttp3.internal.authenticator.JavaNetAuthenticator.authenticate(JavaNetAuthenticator.kt:53)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.followUpRequest(RetryAndFollowUpInterceptor.kt:220)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:108)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
at okhttp3.internal.connection.RealCall.execute(RealCall.kt:154)
The implementation could also NPE on a 407 from an non-proxy host, so I've handled this too.