Uploaded image for project: 'Abdera'
  1. Abdera
  2. ABDERA-231

NullPointerException in RequestOptions.addHeader() when no previous header with that name has been set

    Details

    • Type: Bug
    • Status: Reopened
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 0.4.0
    • Fix Version/s: None
    • Labels:
      None
    • Environment:
      All

      Description

      This code snippet recreates the problem.
      RequestOptions requestOptions = client.getDefaultRequestOptions();
      requestOptions.addHeader("Cookie", "anyNonNullValue");

      Caused by: java.lang.NullPointerException
      at java.util.Arrays$ArrayList.<init>(Arrays.java:2370)
      at java.util.Arrays.asList(Arrays.java:2356)
      at org.apache.abdera.protocol.client.RequestOptions.addHeader(RequestOptions.java:272)
      at org.apache.abdera.protocol.client.RequestOptions.addHeader(RequestOptions.java:263)

      It looks like that RequestOptions.addEncodedHeader() also has the same problem of calling Arrays.asList() before checking for returned null value from getHeaders().get(header)

      One can workaround the problem by calling getHeader() to see if the header has previous values. If it doesn't, just call setHeader().

      This is a regression - addHeader() works fine in 0.2.2.

        Activity

        Hide
        buzzeri Ivan Bondarenko added a comment -

        How to reopen the issue?
        As I understand, the fix has modified the org.apache.abdera.protocol.client.RequestOptions.addHeader(String, String...) method.
        This method is incorrect in 1.1.2 version.
        1) The variable "list" must not be checked for null after line 273: List<String> list = headers != null ? Arrays.asList(headers) : new ArrayList<String>();
        2) More important and a result of 1st point. Value is not assigned to headers if headers haven't such header name before. This is definitely a blocking bug for "addHeader" method.

        Show
        buzzeri Ivan Bondarenko added a comment - How to reopen the issue? As I understand, the fix has modified the org.apache.abdera.protocol.client.RequestOptions.addHeader(String, String...) method. This method is incorrect in 1.1.2 version. 1) The variable "list" must not be checked for null after line 273: List<String> list = headers != null ? Arrays.asList(headers) : new ArrayList<String>(); 2) More important and a result of 1st point. Value is not assigned to headers if headers haven't such header name before. This is definitely a blocking bug for "addHeader" method.
        Hide
        jasnell James M Snell added a comment -

        Fix checked into trunk

        Show
        jasnell James M Snell added a comment - Fix checked into trunk

          People

          • Assignee:
            Unassigned
            Reporter:
            exeternh Jon Hewitt
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:

              Time Tracking

              Estimated:
              Original Estimate - 1h
              1h
              Remaining:
              Remaining Estimate - 1h
              1h
              Logged:
              Time Spent - Not Specified
              Not Specified

                Development