glassfish
  1. glassfish
  2. GLASSFISH-15148

PostConstruct methods not handled properly for managed beans

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: V3
    • Fix Version/s: 4.0
    • Component/s: cdi
    • Labels:
      None

      Description

      In general, handling of PostConstruct methods for managed beans isn't properly taking into
      account method overriding. This works for EJBs, but the implementation needs to be generalized
      to handle managed beans as well.

      Here's a case that fails:

      @ManagedBean
      public class MBBean extends MBBase {
      @PostConstruct
      public void postConstruct() {
      }
      }

      public class MBBase {
      @PostConstruct
      public void postConstruct() {
      }
      }

      The postConstruct method will be called twice.

      Similarly, if a method hides a PostConstruct method in a superclass,
      the method will still be called.

      The same issues probably apply to preDestroy methods.

        Activity

        Hide
        phil.zampino added a comment -

        This was resolved by Weld.

        Show
        phil.zampino added a comment - This was resolved by Weld.
        Hide
        jjsnyder83 added a comment -

        There is a Weld issue for this bug: https://issues.jboss.org/browse/WELD-1225

        Show
        jjsnyder83 added a comment - There is a Weld issue for this bug: https://issues.jboss.org/browse/WELD-1225
        Hide
        Hong Zhang added a comment -

        Thanks Cheng for the analysis. I will let Siva take a look

        Show
        Hong Zhang added a comment - Thanks Cheng for the analysis. I will let Siva take a look
        Hide
        Cheng Fang added a comment -

        This problem only exists for ManagedBean when CDI is enabled, e.g., when beans.xml is present. When subclass overrides PostConstruct method with PostConstruct method, it should only be invoked once, but it is currently invoked twice. When subclass overrides with non-PostConstruct method, it should not be invoked as a lifecycle method, but currently it is still invoked.

        For PreDestroy, when subclass overrides with a PreDestroy method, it's incorrectly invoked twice. When subclass overrides with a non-PreDestroy method, it is not invoked as expected, but the new PreDestroy method added in subclass is also skipped.

        For EJB, all of these cases work correctly, with or without beans.xml.

        Show
        Cheng Fang added a comment - This problem only exists for ManagedBean when CDI is enabled, e.g., when beans.xml is present. When subclass overrides PostConstruct method with PostConstruct method, it should only be invoked once, but it is currently invoked twice. When subclass overrides with non-PostConstruct method, it should not be invoked as a lifecycle method, but currently it is still invoked. For PreDestroy, when subclass overrides with a PreDestroy method, it's incorrectly invoked twice. When subclass overrides with a non-PreDestroy method, it is not invoked as expected, but the new PreDestroy method added in subclass is also skipped. For EJB, all of these cases work correctly, with or without beans.xml.
        Hide
        Hong Zhang added a comment -

        Will look in the future release (not sure who takes the ownership of ManagedBean now (used to be Ken), will keep the issue to me for now).

        Show
        Hong Zhang added a comment - Will look in the future release (not sure who takes the ownership of ManagedBean now (used to be Ken), will keep the issue to me for now).

          People

          • Assignee:
            jjsnyder83
            Reporter:
            Bill Shannon
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: