Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
5.0.3
-
None
Description
After switching to HttpClient 5 I get a NPE in a code that was previously working. It's a pretty simple line
try (CloseableHttpResponse response = httpclient.execute(get, context)) {
which causes this:
Caused by: java.lang.NullPointerException at org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager.release(BasicHttpClientConnectionManager.java:278) at org.apache.hc.client5.http.impl.classic.InternalExecRuntime.discardEndpoint(InternalExecRuntime.java:245) at org.apache.hc.client5.http.impl.classic.InternalExecRuntime.releaseEndpoint(InternalExecRuntime.java:259) at org.apache.hc.client5.http.impl.classic.MainClientExec.execute(MainClientExec.java:136) at org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51) at org.apache.hc.client5.http.impl.classic.ExecChainElement$1.proceed(ExecChainElement.java:57) at org.apache.hc.client5.http.impl.classic.ConnectExec.execute(ConnectExec.java:181) at org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51) at org.apache.hc.client5.http.impl.classic.ExecChainElement$1.proceed(ExecChainElement.java:57) at org.apache.hc.client5.http.impl.classic.ProtocolExec.execute(ProtocolExec.java:172) at org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51) at org.apache.hc.client5.http.impl.classic.ExecChainElement$1.proceed(ExecChainElement.java:57) at org.apache.hc.client5.http.impl.classic.HttpRequestRetryExec.execute(HttpRequestRetryExec.java:93) at org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51) at org.apache.hc.client5.http.impl.classic.ExecChainElement$1.proceed(ExecChainElement.java:57) at org.apache.hc.client5.http.impl.classic.ContentCompressionExec.execute(ContentCompressionExec.java:128) at org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51) at org.apache.hc.client5.http.impl.classic.InternalHttpClient.doExecute(InternalHttpClient.java:178) at org.apache.hc.client5.http.impl.classic.CloseableHttpClient.execute(CloseableHttpClient.java:75)
The request itself seems to be working, the problem is closing connection (I'm using a NoConnectionReuseStrategy which mimics the old Strategy available in version 4). This is in the log before crash:
[2020-11-02 16:35:53.389] [org.apache.hc.client5.http.impl.io.DefaultManagedHttpClientConnection] [main] [DEBUG] [org.apache.hc.client5.http.impl.io.DefaultManagedHttpClientConnection] [close] [143] : http-outgoing-0: close connection IMMEDIATE [2020-11-02 16:35:53.390] [org.apache.hc.client5.http.impl.classic.InternalHttpClient] [main] [DEBUG] [org.apache.hc.client5.http.impl.classic.InternalExecRuntime] [discardEndpoint] [239] : InternalConnectionEndpoint-5175d9ad: endpoint closed [2020-11-02 16:35:53.390] [org.apache.hc.client5.http.impl.classic.InternalHttpClient] [main] [DEBUG] [org.apache.hc.client5.http.impl.classic.InternalExecRuntime] [discardEndpoint] [243] : InternalConnectionEndpoint-5175d9ad: discarding endpoint [2020-11-02 16:35:53.390] [org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager] [main] [DEBUG] [org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager] [closeConnection] [209] : Closing connection GRACEFUL
Seems like the code doesn't check whether conn is null when calling conn.passivate(); (but it does check for null when doing debug logging at start of release method).