Details
-
Bug
-
Status: Resolved
-
Trivial
-
Resolution: Fixed
-
5.3
-
None
Description
If you enable debug logging, HttpClient5 will give you free NPEs in certain classes, such as PoolingHttpClientConnectionManager.
On line 410-413 of this class there is the following code:
} else { if (LOG.isDebugEnabled()) { LOG.debug("{} connection is not kept alive(isConsistent:{})", ConnPoolSupport.getId(endpoint), conn.isConsistent()); } }
This else is related to the boolean `reusable` being false. However, one of the possible causes of this boolean being false is `conn` being `null`:
boolean reusable = conn != null && conn.isOpen() && conn.isConsistent();
If `conn` is `null` then `conn.isConsistent()` throws an NPE during the creation of the debug message.
java.lang.NullPointerException: Cannot invoke "org.apache.hc.client5.http.io.ManagedHttpClientConnection.isConsistent()" because "conn" is null at org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager.release(PoolingHttpClientConnectionManager.java:412) at org.apache.hc.client5.http.impl.classic.InternalExecRuntime.discardEndpoint(InternalExecRuntime.java:246) at org.apache.hc.client5.http.impl.classic.InternalExecRuntime.releaseEndpoint(InternalExecRuntime.java:260) at org.apache.hc.client5.http.impl.classic.ResponseEntityProxy.releaseConnection(ResponseEntityProxy.java:80) at org.apache.hc.client5.http.impl.classic.ResponseEntityProxy.eofDetected(ResponseEntityProxy.java:115) at org.apache.hc.core5.http.io.EofSensorInputStream.checkEOF(EofSensorInputStream.java:199) at org.apache.hc.core5.http.io.EofSensorInputStream.read(EofSensorInputStream.java:136) at java.base/sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:270) at java.base/sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:313) at java.base/sun.nio.cs.StreamDecoder.read(StreamDecoder.java:188) at java.base/java.io.InputStreamReader.read(InputStreamReader.java:177) at java.base/java.io.Reader.read(Reader.java:250) at org.apache.hc.core5.http.io.entity.EntityUtils.toCharArrayBuffer(EntityUtils.java:188) at org.apache.hc.core5.http.io.entity.EntityUtils.toString(EntityUtils.java:231) at org.apache.hc.core5.http.io.entity.EntityUtils.toString(EntityUtils.java:292) at org.apache.hc.core5.http.io.entity.EntityUtils.toString(EntityUtils.java:253) at com.github.tomakehurst.wiremock.common.HttpClientUtils.getEntityAsStringAndCloseStream(HttpClientUtils.java:35) at com.github.tomakehurst.wiremock.client.HttpAdminClient.safelyExecuteRequest(HttpAdminClient.java:535) at com.github.tomakehurst.wiremock.client.HttpAdminClient.executeRequest(HttpAdminClient.java:507) at com.github.tomakehurst.wiremock.client.HttpAdminClient.executeRequest(HttpAdminClient.java:483) at com.github.tomakehurst.wiremock.client.HttpAdminClient.addStubMapping(HttpAdminClient.java:150) at com.github.tomakehurst.wiremock.client.WireMock.register(WireMock.java:446) at com.github.tomakehurst.wiremock.client.WireMock.register(WireMock.java:441) at com.github.tomakehurst.wiremock.client.WireMock.givenThat(WireMock.java:130) at com.github.tomakehurst.wiremock.client.WireMock.stubFor(WireMock.java:134)