Uploaded image for project: 'TomEE'
  1. TomEE
  2. TOMEE-4333

NotSerializableException with @Inject HttpServletRequest

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 10.0.0-M1, 9.1.3
    • 10.0.0-M2, 9.1.4
    • None
    • None

    Description

      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
      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():

      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.

      Attachments

        Activity

          People

            jgallimore Jonathan Gallimore
            jgallimore Jonathan Gallimore
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 1h
                1h