In order to support MVC async methods while testing with MockMvc, synchronizes any access to MockHttpServletResponse HTTP headers. It avoids ConcurrentModificationException thrown when e.g. 2 different threads read and write the header's map.

Link to a project reproducing the issue here Related/similar to #23460

Comment From: rstoyanchev

This is according to the Servlet spec 2.3.3.4:

Other than the startAsync and complete methods, implementations of the request and response objects are not guaranteed to be thread safe. This means that they should either only be used within the scope of the request handling thread or the application must ensure that access to the request and response objects are thread safe.

So access to the response must be synchronized. The response itself is not.

23460 should have been rejected as well. There was also an actual issue involving Spring Security and SSE and a similar exception but I can't find it at the moment. I believe it was transferred to be addressed within Spring Security.