Description
Ricardo identified a serious bug in ClickServlet where we check if Context should be cleared from the ThreadLocal.
Currently we check that if the forwarded request is of type ClickRequestWrapper, we do not clear the ThreadLocal, otherwise we do.
I wrongly concluded that the forwarded request will always be the request passed into #requestDispatcher.forward(..).
However the spec RequestDispatcher#forward states:
"The request and response parameters must be either the same objects as were passed to the calling servlet's service method or be subclasses of the
ServletRequestWrapper or ServletResponseWrapper classes that wrap them."
meaning the request we pass to #forward might be wrapped by a subclass of ServletRequestWrapper. Jetty 5.12 does this by wrapping ClickRequestWrapper in a class called "DispatcherRequest".
We can fix the problem by unwinding the request and look for an instance of ClickRequestWrapper.
Unfortunately the above fix is not enough. After patching ClickServlet with the above fix, Jetty would not forward to the correct page. Instead it kept forwarding back to the original requests path.
I think the problem is that ClickRequestWrapper references the original request instead of "DispatcherRequest". Will investigate further.