Description
Given this CDI Bean:
@SessionScoped
@Named
public class MyPageBean implements Serializable
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
From: https://www.mail-archive.com/dev@tomee.apache.org/msg18097.html
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():
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.