Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

NPE when @SetsCookie is used but cookie was *not* set by the server #855

Description

@kutsal

Tested this on version 3.0.

Given an interface like this:

@Rest(converters = { StringHttpMessageConverter.class, FormHttpMessageConverter.class })
public interface MyCoolRestInterface {
    @Post("/very/cool?foo={bar}")
    @SetsCookie({ "YUMMY" })
    @Accept(MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    String veryCool(MultiValueMap<String, String> params, boolean bar);

    @Get("needs/cookie")
    @RequiresCookie("YUMMY")
    String needsCookie();
}

When the response comes back from the server and YUMMY _is not_ set, we get an NPE at the for loop in the generated code (see RIGHT HERE below):

@Override
public String veryCool(MultiValueMap<String, String> params, boolean bar) {
    ...
    String[] requestedCookies = new String[] {"YUMMY"};
    List<String> allCookies = response.getHeaders().get("Set-Cookie");
    *** RIGHT HERE *** > for (String rawCookie: allCookies) {
        ...
}

because _Set-Cookie_ header is not present, and allCookies is null. Well, at least in my case it is. This should be better guarded by a null check of the list returned by the get() call.

Activity

  1. DayS commented on Jan 2, 2014

    @DayS
    Contributor

    Thanks for pointing this out. I'll fix it right now

  2. DayS commented on Jan 2, 2014

    @DayS
    Contributor

    This should be fixed in the 3.0.1 hotfix which will be released soon.
    In the meantime you can use 3.1-SNAPSHOT

  3. kutsal commented on Jan 2, 2014

    @kutsal
    Author

    Thank you for fixing this so quickly.

    Sent from Yahoo Mail on Android

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions