[GLASSFISH-15148] PostConstruct methods not handled properly for managed beans Created: 13/Dec/10  Updated: 19/Mar/13  Resolved: 19/Mar/13

Status: Closed
Project: glassfish
Component/s: cdi
Affects Version/s: V3
Fix Version/s: 4.0

Type: Bug Priority: Major
Reporter: Bill Shannon Assignee: jjsnyder83
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Tags: 3_1-exclude, req-weld-fix


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:

public class MBBean extends MBBase {
public void postConstruct() {

public class MBBase {
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.

Comment by Hong Zhang [ 13/Dec/10 ]

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).

Comment by Cheng Fang [ 16/Feb/11 ]

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.

Comment by Hong Zhang [ 16/Feb/11 ]

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

Comment by jjsnyder83 [ 15/Oct/12 ]

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

Comment by phil.zampino [ 19/Mar/13 ]

This was resolved by Weld.

Generated at Tue Mar 28 23:04:03 UTC 2017 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.