Uploaded image for project: 'WildFly'
  1. WildFly
  2. WFLY-19610

@PostConstruct on Servlet may be called twice

XMLWordPrintable

    • Hide

      I've tested this on Wildfly 27.0.1 and up. 

      Deploy the attached war.

      Issue a curl command:

      <~/f/c/d/m/j/demo-base>-> curl http://localhost:8080/wf-repro/simple
      bean=[repro.SimpleBean@3348d23], env-entry=[33], post-construct-count=[2]⏎
      Show
      I've tested this on Wildfly 27.0.1 and up.   Deploy the attached war. Issue a curl command: <~/f/c/d/m/j/demo-base>-> curl http://localhost:8080/wf-repro/simple bean=[repro.SimpleBean@3348d23], env-entry=[33], post-construct-count=[2]⏎
    • ---
    • ---

      We have a tool that will scan a web archive and wrap each filter, listener, and servlet in order to provide customized session support in a "portable" fashion.  This has been working fine using pre-annotation web applications.

      We've recently began updating our framework to support the latest Servlet features and have run into an issue with @PostConstruct (probably @PreDestroy as well, but I haven't verified it yet) being called twice.  In this case, there is a Servlet included in a web-fragment jar that has @PostConstruct defined.  The web-fragment.xml doesn't reference this servlet, but instead references a wrapper around it.  When the init() method is called on the wrapper, it calls ServletContext.createServlet() with the wrapped servlet class.  After this call returns, the counter in the @PostConstruct implementation has been invoked twice. 

      I've attached (in call order) the call stacks I captured from Intellij. 

      See the attached test case: wf-repro.tar.gz

        1. Screenshot 2024-08-06 at 7.58.21 AM.png
          125 kB
          Ryan Lubke
        2. Screenshot 2024-08-06 at 7.58.21 AM-1.png
          125 kB
          Ryan Lubke
        3. Screenshot 2024-08-06 at 9.18.39 AM.png
          81 kB
          Ryan Lubke
        4. wf-repro.tar.gz
          6 kB
          Ryan Lubke

              jaslee@redhat.com Jason Lee
              lubkerk Ryan Lubke (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: