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.