You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by se...@apache.org on 2011/11/27 16:25:54 UTC

svn commit: r1206731 - /httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java

Author: sebb
Date: Sun Nov 27 15:25:53 2011
New Revision: 1206731

URL: http://svn.apache.org/viewvc?rev=1206731&view=rev
Log:
Not sure that instream can be null, but assuming it can, there's no point entering the try block if it's null. This avoids NPE warning

Modified:
    httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java

Modified: httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java?rev=1206731&r1=1206730&r2=1206731&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java Sun Nov 27 15:25:53 2011
@@ -180,18 +180,18 @@ public class TestHttpCore implements Tes
                         httpexecutor.postProcess(response, httpproc, context);
 
                         HttpEntity entity = response.getEntity();
-                        if (entity != null) {
+                        if (entity != null) { // TODO can this be null?
                             InputStream instream = entity.getContent();
-                            try {
+                            if (instream != null) {
                                 contentLen = 0;
-                                if (instream != null) {
-                                    int l = 0;
-                                    while ((l = instream.read(buffer)) != -1) {
-                                        contentLen += l;
-                                    }
+                                try {
+                                        int l = 0;
+                                        while ((l = instream.read(buffer)) != -1) {
+                                            contentLen += l;
+                                        }
+                                } finally {
+                                    instream.close();
                                 }
-                            } finally {
-                                instream.close();
                             }
                         }
                         if (connStrategy.keepAlive(response, context)) {



Re: svn commit: r1206731

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Sun, 2011-11-27 at 23:23 +0000, sebb wrote:
> On 27 November 2011 16:06, Oleg Kalnichevski <ol...@apache.org> wrote:
> > On Sun, 2011-11-27 at 15:25 +0000, sebb@apache.org wrote:
> >> Author: sebb
> >> Date: Sun Nov 27 15:25:53 2011
> >> New Revision: 1206731
> >>
> >> URL: http://svn.apache.org/viewvc?rev=1206731&view=rev
> >> Log:
> >> Not sure that instream can be null, but assuming it can, there's no point entering the try block if it's null. This avoids NPE warning
> >>
> >> Modified:
> >>     httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java
> >>
> >> Modified: httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java
> >> URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java?rev=1206731&r1=1206730&r2=1206731&view=diff
> >> ==============================================================================
> >> --- httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java (original)
> >> +++ httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java Sun Nov 27 15:25:53 2011
> >> @@ -180,18 +180,18 @@ public class TestHttpCore implements Tes
> >>                          httpexecutor.postProcess(response, httpproc, context);
> >>
> >>                          HttpEntity entity = response.getEntity();
> >> -                        if (entity != null) {
> >> +                        if (entity != null) { // TODO can this be null?
> 
> Oops, added comment to the wrong line ...
> 
> >>                              InputStream instream = entity.getContent();
> >> -                            try {
> >> +                            if (instream != null) {
> 
> Intended to put it here.
> 
> >
> > HttpEntity may be null for those responses that are not allowed to
> > enclose an entity by the HTTP spec (such as 304 Not Modified).
> >
> > InputStream may not be null unless the message is received over a
> > non-blocking connection. This applies to HttpCore NIO and
> > HttpAsyncClient only.
> 
> AFAICT, TestHttpCore does not test NIO or async, so presumably the
> null check could be removed?
> Likewise in TestHttpClient4?
> 

Yes, it could be.

Oleg




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


Re: svn commit: r1206731

Posted by sebb <se...@gmail.com>.
On 27 November 2011 16:06, Oleg Kalnichevski <ol...@apache.org> wrote:
> On Sun, 2011-11-27 at 15:25 +0000, sebb@apache.org wrote:
>> Author: sebb
>> Date: Sun Nov 27 15:25:53 2011
>> New Revision: 1206731
>>
>> URL: http://svn.apache.org/viewvc?rev=1206731&view=rev
>> Log:
>> Not sure that instream can be null, but assuming it can, there's no point entering the try block if it's null. This avoids NPE warning
>>
>> Modified:
>>     httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java
>>
>> Modified: httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java
>> URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java?rev=1206731&r1=1206730&r2=1206731&view=diff
>> ==============================================================================
>> --- httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java (original)
>> +++ httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java Sun Nov 27 15:25:53 2011
>> @@ -180,18 +180,18 @@ public class TestHttpCore implements Tes
>>                          httpexecutor.postProcess(response, httpproc, context);
>>
>>                          HttpEntity entity = response.getEntity();
>> -                        if (entity != null) {
>> +                        if (entity != null) { // TODO can this be null?

Oops, added comment to the wrong line ...

>>                              InputStream instream = entity.getContent();
>> -                            try {
>> +                            if (instream != null) {

Intended to put it here.

>
> HttpEntity may be null for those responses that are not allowed to
> enclose an entity by the HTTP spec (such as 304 Not Modified).
>
> InputStream may not be null unless the message is received over a
> non-blocking connection. This applies to HttpCore NIO and
> HttpAsyncClient only.

AFAICT, TestHttpCore does not test NIO or async, so presumably the
null check could be removed?
Likewise in TestHttpClient4?

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


Re: svn commit: r1206731

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Sun, 2011-11-27 at 15:25 +0000, sebb@apache.org wrote:
> Author: sebb
> Date: Sun Nov 27 15:25:53 2011
> New Revision: 1206731
> 
> URL: http://svn.apache.org/viewvc?rev=1206731&view=rev
> Log:
> Not sure that instream can be null, but assuming it can, there's no point entering the try block if it's null. This avoids NPE warning
> 
> Modified:
>     httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java
> 
> Modified: httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java
> URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java?rev=1206731&r1=1206730&r2=1206731&view=diff
> ==============================================================================
> --- httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java (original)
> +++ httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java Sun Nov 27 15:25:53 2011
> @@ -180,18 +180,18 @@ public class TestHttpCore implements Tes
>                          httpexecutor.postProcess(response, httpproc, context);
>  
>                          HttpEntity entity = response.getEntity();
> -                        if (entity != null) {
> +                        if (entity != null) { // TODO can this be null?
>                              InputStream instream = entity.getContent();
> -                            try {
> +                            if (instream != null) {

HttpEntity may be null for those responses that are not allowed to
enclose an entity by the HTTP spec (such as 304 Not Modified). 

InputStream may not be null unless the message is received over a
non-blocking connection. This applies to HttpCore NIO and
HttpAsyncClient only.

Oleg



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