Hello TomEE friends, I was looking to patch a bug we encountered and could
use some advice from the other committers.

Given this CDI Bean:

@SessionScoped
@Named
public class MyPageBean implements Serializable {
 @Inject private HttpServletRequest req;
... use the bean somewhere in EL
}

This will result in an exception when serializing the Session (For session
replication or passivation): java.lang.RuntimeException:
java.lang.RuntimeException: java.io.NotSerializableException:
org.apache.openejb.cdi.Proxys$ThreadLocalHandler

Looking at the Proxys.java code, it contains a private static class called
ThreadLocalHandler, that is indeed not Serializable. For fun, I made
ThreadLocalHandler implement Serializable, but that just resulted in
another error because ThreadLocalHandler contains a ThreadLocal field which
is definitely not Serializable.

ThreadLocalHandler for HttpServletRequest is invoked by
TomcatWebappBuilder.setComponentsUsedByCDI():

https://github.com/apache/tomee/blob/tomee-8.x/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java#L358

I'm at a bit of a loss on how to fix this. My assumption is the
ThreadLocalHandler was designed as a generic proxy object that defers to an
internal ThreadLocal object. I wonder if marking the ThreadLocal as
transient is sufficient, but I could use some input.

Thank you,

-- 
Jonathan | [email protected]
Pessimists, see a jar as half empty. Optimists, in contrast, see it as half
full.
Engineers, of course, understand the glass is twice as big as it needs to
be.

Reply via email to