Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MockHttpServletRequest returns empty cookies array instead of null if instance is built using MockHttpServletRequestBuilder [SPR-13314] #17899

Closed
spring-projects-issues opened this issue Aug 4, 2015 · 1 comment
Assignees
Labels
in: test Issues in the test module type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Joan Parera opened SPR-13314 and commented

If a MockHttpServletRequest is built using the MockHttpServletRequestBuilder in Spring MVC Test and no cookies are added, the getCookies() method returns an empty array.

However, according to the Servlet API, an implementation of HttpServletRequest.getCookies() must return null if the request has no cookies.


Affects: 3.2 GA

Referenced from: commits 93c07e7

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

Fixed in GitHub commit 93c07e7:

Return null instead of empty cookies array in Spring MVC Test

Prior to this commit, MockHttpServletRequestBuilder always supplied an array of cookies to the MockHttpServletRequest that it built, even if the array was empty.

However, this violates the contract of HttpServletRequest. According to the Servlet API, the getCookies() method "returns null if no cookies were sent."

This commit ensures that MockHttpServletRequestBuilder no longer configures an empty array of cookies in the mock request that it builds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants