You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Adam Michalik (JIRA)" <ji...@apache.org> on 2016/10/26 09:13:58 UTC

[jira] [Comment Edited] (HTTPCORE-437) NullPointerException in HeaderGroup.getHeaders

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

Adam Michalik edited comment on HTTPCORE-437 at 10/26/16 9:13 AM:
------------------------------------------------------------------

I have two implementations of {{Header}}: {{BasicHeader}} and {{BufferedHeader}} on the classpath. Both seem to have checks against it:

{code:java}
    public BasicHeader(final String name, final String value) {
        super();
        this.name = Args.notNull(name, "Name"); // explicit check
        this.value = value;
    }
{code}

{code:java}
    public BufferedHeader(final CharArrayBuffer buffer)
        throws ParseException {

        super();
        Args.notNull(buffer, "Char array buffer");
        final int colon = buffer.indexOf(':');
        if (colon == -1) {
            throw new ParseException
                ("Invalid header: " + buffer.toString());
        }
        final String s = buffer.substringTrimmed(0, colon);
        if (s.length() == 0) {
            throw new ParseException
                ("Invalid header: " + buffer.toString());
        }
        this.buffer = buffer;
        this.name = s; // not null, otherwise s.length() above would have thrown NPE
        this.valuePos = colon + 1;
    }
{code}


was (Author: hattifnat):
I have two implementations of {{Header}}: {{BasicHeader}} and {{BufferedHeader}}. Both seem to have checks against it:

{code:java}
    public BasicHeader(final String name, final String value) {
        super();
        this.name = Args.notNull(name, "Name"); // explicit check
        this.value = value;
    }
{code}

{code:java}
    public BufferedHeader(final CharArrayBuffer buffer)
        throws ParseException {

        super();
        Args.notNull(buffer, "Char array buffer");
        final int colon = buffer.indexOf(':');
        if (colon == -1) {
            throw new ParseException
                ("Invalid header: " + buffer.toString());
        }
        final String s = buffer.substringTrimmed(0, colon);
        if (s.length() == 0) {
            throw new ParseException
                ("Invalid header: " + buffer.toString());
        }
        this.buffer = buffer;
        this.name = s; // not null, otherwise s.length() above would have thrown NPE
        this.valuePos = colon + 1;
    }
{code}

> NullPointerException in HeaderGroup.getHeaders
> ----------------------------------------------
>
>                 Key: HTTPCORE-437
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-437
>             Project: HttpComponents HttpCore
>          Issue Type: Bug
>          Components: HttpCore
>    Affects Versions: 4.4.5
>            Reporter: Adam Michalik
>
> I'm using HttpClient in multithreaded environment with PoolingHttpClientConnectionManager. Once in a while I get an exception whose root cause is
> {code}
>     Caused by: java.lang.NullPointerException: null
>         at org.apache.http.message.HeaderGroup.getHeaders(HeaderGroup.java:182)
>         at org.apache.http.message.AbstractHttpMessage.getHeaders(AbstractHttpMessage.java:73)
>         at org.apache.http.impl.client.DefaultClientConnectionReuseStrategy.keepAlive(DefaultClientConnectionReuseStrategy.java:51)
>         at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:274)
>         at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
>         at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
>         at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
>         at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
>         at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
>         at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:220)
>         at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:164)
> {code}
> The {{getHeaders}} method is 
> {code:java}
>     public Header[] getHeaders(final String name) {
>         List<Header> headersFound = null;
>         for (int i = 0; i < this.headers.size(); i++) {
>             final Header header = this.headers.get(i);
>             if (header.getName().equalsIgnoreCase(name)) { // NPE HERE
>                 if (headersFound == null) {
>                     headersFound = new ArrayList<Header>();
>                 }
>                 headersFound.add(header);
>             }
>         }
>         return headersFound != null ? headersFound.toArray(new Header[headersFound.size()]) : EMPTY;
>     }
> {code}
> I looked around in the {{HeaderGroup}} class and I see that every modification to the {{headers}} list has a null-check. Also, the {{BasicHeader}} and {{BufferedHeader}} have null-checks so that {{name}} cannot be null. How can this be occurring?
> The issue happens on production, around 10 exceptions in the last 12 hours out of 1 000 000 requests done in total.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

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