Hello,

We encountered random failures in our integration tests.

We are implementing a custom ThreadPoolTaskExecutor, to run ScopeRequest aware threads. As describe here : https://stackoverflow.com/questions/23732089/how-to-enable-request-scope-in-async-task-executor

We ran into a random issue, when multiple thread try to access org.springframework.mock.web.MockHttpServletRequest#getAttribute at the exact same time.

Sometime, the method return Null, instead of the attribute. Causing in our case the bean recreation in the middle of the transaction.

Seems that MockHttpServletRequest class initialize the attribues map with a LinkedHashMap. Which is not thread safe. this.attributes = new LinkedHashMa

Out of testing scope, in catalina implementation, a ConcurrentHashMap is used, preventing this issue.

Is this a bug? Or a limitation of spring-test ?

Best Regards

Comment From: snicoll

I don't think this is a bug. There's nothing in HttpServletRequestthat I can see that requires it to be thread-safe. You've taken an example with Tomcat, but @sbrannen checked other servlet containers and they don't expose such behavior.

I wouldn't expect HttpServletRequest to be passed in and used in several threads, be it in test context or not.