Uploaded image for project: 'Weld'
  1. Weld
  2. WELD-2256

CDI.current() fails in portable extension observer methods

XMLWordPrintable

      The specification indicates that a portable extension may acquire a BeanManager by doing:

      final BeanManager beanManager = CDI.current().getBeanManager();
      

      The relevant specification text:

      A portable extension or other object may obtain a reference to the current container by calling CDI.current(). CDI.getBeanManager() may be called at any time after the container fires the BeforeBeanDiscovery container lifecycle event until the container fires the BeforeShutdown container lifecycle event.

      This fails in (at least) an AfterDeploymentValidation lifecycle event observer method. I will attach a reproducer shortly.

      I believe that the root cause is that the WeldContainer#RUNNING_CONTAINER_IDS collection, which backs the CDI#current() machinery, is not updated until after the container is officially placed into service. This is too late if I'm reading the specification right.

            mkouba@redhat.com Martin Kouba
            ljnelson+github@gmail.com Laird Nelson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: