You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2013/05/08 16:04:29 UTC

svn commit: r1480281 - in /httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client: InternalHttpAsyncClient.java MinimalHttpAsyncClient.java

Author: olegk
Date: Wed May  8 14:04:29 2013
New Revision: 1480281

URL: http://svn.apache.org/r1480281
Log:
Suppress resource leak warning for HttpClientExchangeHandler instances

Modified:
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClient.java

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java?rev=1480281&r1=1480280&r2=1480281&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java Wed May  8 14:04:29 2013
@@ -175,6 +175,7 @@ class InternalHttpAsyncClient extends Cl
             context != null ? context : new BasicHttpContext());
         setupContext(localcontext);
 
+        @SuppressWarnings("resource")
         final DefaultClientExchangeHandlerImpl<T> handler = new DefaultClientExchangeHandlerImpl<T>(
             this.log,
             requestProducer,

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClient.java?rev=1480281&r1=1480280&r2=1480281&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClient.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClient.java Wed May  8 14:04:29 2013
@@ -149,6 +149,7 @@ class MinimalHttpAsyncClient extends Clo
         final HttpClientContext localcontext = HttpClientContext.adapt(
             context != null ? context : new BasicHttpContext());
 
+        @SuppressWarnings("resource")
         final MinimalClientExchangeHandlerImpl<T> handler = new MinimalClientExchangeHandlerImpl<T>(
             this.log,
             requestProducer,



Re: svn commit: r1480281

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2013-05-08 at 15:38 +0100, sebb wrote:
> On 8 May 2013 15:04,  <ol...@apache.org> wrote:
> > Author: olegk
> > Date: Wed May  8 14:04:29 2013
> > New Revision: 1480281
> >
> > URL: http://svn.apache.org/r1480281
> > Log:
> > Suppress resource leak warning for HttpClientExchangeHandler instances
> >
> > Modified:
> >     httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java
> >     httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClient.java
> >
> > Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java
> > URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java?rev=1480281&r1=1480280&r2=1480281&view=diff
> > ==============================================================================
> > --- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java (original)
> > +++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java Wed May  8 14:04:29 2013
> > @@ -175,6 +175,7 @@ class InternalHttpAsyncClient extends Cl
> >              context != null ? context : new BasicHttpContext());
> >          setupContext(localcontext);
> >
> > +        @SuppressWarnings("resource")
> 
> Why is it safe to ignore the warning?
> 

Well, the usual delights of asynchronous programming. Execution flow is
no longer context (thread) bound and one can no longer rely upon
try-catch-finally to ensure resource deallocation. Instead resource
deallocation can be triggered by multiple events (execution completed,
execution failed, execution canceled, etc). Static code analysis such as
employed by Eclipse to ensure Closeable(s) always get closed no longer
works here.

Oleg  



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Re: svn commit: r1480281 - in /httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client: InternalHttpAsyncClient.java MinimalHttpAsyncClient.java

Posted by sebb <se...@gmail.com>.
On 8 May 2013 15:04,  <ol...@apache.org> wrote:
> Author: olegk
> Date: Wed May  8 14:04:29 2013
> New Revision: 1480281
>
> URL: http://svn.apache.org/r1480281
> Log:
> Suppress resource leak warning for HttpClientExchangeHandler instances
>
> Modified:
>     httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java
>     httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClient.java
>
> Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java
> URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java?rev=1480281&r1=1480280&r2=1480281&view=diff
> ==============================================================================
> --- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java (original)
> +++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java Wed May  8 14:04:29 2013
> @@ -175,6 +175,7 @@ class InternalHttpAsyncClient extends Cl
>              context != null ? context : new BasicHttpContext());
>          setupContext(localcontext);
>
> +        @SuppressWarnings("resource")

Why is it safe to ignore the warning?

It would help to have an inline comment to explain the reason it's OK.

>          final DefaultClientExchangeHandlerImpl<T> handler = new DefaultClientExchangeHandlerImpl<T>(
>              this.log,
>              requestProducer,
>
> Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClient.java
> URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClient.java?rev=1480281&r1=1480280&r2=1480281&view=diff
> ==============================================================================
> --- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClient.java (original)
> +++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClient.java Wed May  8 14:04:29 2013
> @@ -149,6 +149,7 @@ class MinimalHttpAsyncClient extends Clo
>          final HttpClientContext localcontext = HttpClientContext.adapt(
>              context != null ? context : new BasicHttpContext());
>
> +        @SuppressWarnings("resource")
>          final MinimalClientExchangeHandlerImpl<T> handler = new MinimalClientExchangeHandlerImpl<T>(
>              this.log,
>              requestProducer,
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org