#25 MockHttpServletRequest getCookies() should return null

closed
None
5
2008-06-27
2007-08-02
shermand56
No

The HttpServletRequest interface specifies that getCookies() should return an array of type Cookie, or null if the request has no cookies.

MockHttpServletRequest instantiates an empty ArrayList when the object is created, which causes getCookies() to return an empty array instead of null when there are no cookies on the request.

Suggested changes:

in resetAll():
...
cookies = null;
...

Then fix the getter/setter pair:
public Cookie[] getCookies()
{
return (cookies==null) ? cookies : (Cookie[])cookies.toArray(new Cookie[cookies.size()]);
}

public void addCookie(Cookie cookie)
{
if (null == cookies) {
cookies = new ArrayList();
}
cookies.add(cookie);
}

Discussion

  • Alwin Ibba

    Alwin Ibba - 2007-08-03
    • assigned_to: nobody --> aibba
     
  • Alwin Ibba

    Alwin Ibba - 2007-08-03

    Logged In: YES
    user_id=804648
    Originator: NO

    Thanks. Will be fixed.

     
  • Alwin Ibba

    Alwin Ibba - 2008-06-27
    • status: open --> closed