[ 
https://issues.apache.org/jira/browse/HTTPCLIENT-2125?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17224748#comment-17224748
 ] 

Dominik Derwiński commented on HTTPCLIENT-2125:
-----------------------------------------------

I can confirm the bug is gone when disabling 
.setConnectionReuseStrategy(NoConnectionReuseStrategy.INSTANCE)
where NoConnectionReuseStrategy is
{noformat}
@Contract(threading = ThreadingBehavior.IMMUTABLE)
public final class NoConnectionReuseStrategy implements ConnectionReuseStrategy 
{

    public static final NoConnectionReuseStrategy INSTANCE = new 
NoConnectionReuseStrategy();

    public NoConnectionReuseStrategy() {
        super();
    }

    @Override
    public boolean keepAlive(HttpRequest request, HttpResponse response, 
HttpContext context) {
        return false;
    }

}
{noformat}

> NullPointerException in BasicHttpClientConnectionManager
> --------------------------------------------------------
>
>                 Key: HTTPCLIENT-2125
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2125
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient (classic)
>    Affects Versions: 5.0.3
>            Reporter: Dominik Derwiński
>            Priority: Major
>
> After switching to HttpClient 5 I get a NPE in a code that was previously 
> working. It's a pretty simple line
> {noformat}
> try (CloseableHttpResponse response = httpclient.execute(get, context)) {
> {noformat}
> which causes this:
> {noformat}
> 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)
> {noformat}
> 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:
> {noformat}
> [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
> {noformat}
>  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).



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to