govindprasadgupta / oauth

Automatically exported from code.google.com/p/oauth
0 stars 0 forks source link

NullPointerException in HttpMethodResponse (java) #211

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
see line 106

if (httpRequest instanceof HttpEntityEnclosingRequest) {
                HttpEntityEnclosingRequest r = (HttpEntityEnclosingRequest) httpRequest;
                long contentLength = r.getEntity().getContentLength();
                if (contentLength >= 0) {
                    request.append("Content-Length: ").append(contentLength).append(EOL);
                }
            }

but really r.getEntity() can be null in we use POST and body is null. See line 
70 in HttpClient4.java

if (isPost || isPut) {
            HttpEntityEnclosingRequestBase entityEnclosingMethod = isPost ? new HttpPost(url) : new HttpPut(url);
            if (body != null) {
                ExcerptInputStream e = new ExcerptInputStream(body);
                excerpt = e.getExcerpt();
                String length = request.removeHeaders(HttpMessage.CONTENT_LENGTH);
                entityEnclosingMethod
                        .setEntity(new InputStreamEntity(e, (length == null) ? -1 : Long.parseLong(length)));
            }

so setEntity calls only when (body != null). In other way Entity will be null; 
And in dump in HttpMethodResponse  we get NullPointer.

Original issue reported on code.google.com by Gls...@gmail.com on 9 Sep 2011 at 12:37