In our Spring boot application we're using the MockHttpServletRequest in our unit tests. Sometimes the content of the mocked request is null. In this case, when getting the reader, we're getting an instance of a StringReader for an empty string. The read method immediately returns -1 which means there is no content. So far this is the correct behaviour.

A problem occurs when you're creating multiple instances of the MockHttpServletRequest with its content set to null. When getting the reader I would expect getting a new reader instance for each mocked request. This is not the case, since if the content is null, a reader instance stored in a static variable will be returned. This is a problem because once reader is used for the first mocked request, it cannot be used for the second mocked request because the stream used by the reader is already closed.

To fix this issue I'm returning a new reader instance instead of using a static variable to always return the same instance. A unit test was added to reproduce the issue and to assert the fix is working as expected.

Comment From: pivotal-cla

@ghost Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

Comment From: pivotal-cla

@ghost Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

Comment From: pivotal-cla

@ghost Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

Comment From: pivotal-cla

@ghost Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.