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

@kutsal

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.

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