MockHttpServletRequest should not use a shared reader when no content is available #32820
Labels
in: test
Issues in the test module
status: backported
An issue that has been backported to maintenance branches
type: bug
A general bug
Milestone
Affects: At least from 5.3.31 to latest (2024-05-14)
If you create two different instances of
MockHttpServletRequest
without specifying content and try to use the reader of each of them. The second one will raise an exception as all these instances share the same underlying reader (EMPTY_BUFFERED_READER -> https://github.com/spring-projects/spring-framework/blob/main/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletRequest.java#L741).Here is a kotlin example of it:
If you run the first test alone in its own JVM, it'll work.
If you run the second test alone, it'll fail on the second MockHttpServletRequest.reader use.
If you repeat the first test at least twice in the same JVM, only the first execution will run fine, all the other ones will fail.
The text was updated successfully, but these errors were encountered: