Issue Details (XML | Word | Printable)

Key: GLASSFISH-15148
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: jjsnyder83
Reporter: Bill Shannon
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
glassfish

PostConstruct methods not handled properly for managed beans

Created: 13/Dec/10 03:57 PM   Updated: 19/Mar/13 09:12 PM   Resolved: 19/Mar/13 09:12 PM
Component/s: cdi
Affects Version/s: V3
Fix Version/s: 4.0

Time Tracking:
Not Specified

Tags: 3_1-exclude req-weld-fix
Participants: Bill Shannon, Cheng Fang, Hong Zhang, jjsnyder83 and phil.zampino


 Description  « Hide

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.



Bill Shannon made changes - 13/Dec/10 03:57 PM
Field Original Value New Value
Affects Version/s V3 [ 10981 ]
Hong Zhang added a comment - 13/Dec/10 06:22 PM

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


Hong Zhang made changes - 13/Dec/10 06:22 PM
Fix Version/s 3.2 [ 10969 ]
Tags 3_1-exclude
Cheng Fang added a comment - 16/Feb/11 12:05 PM

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.


Cheng Fang made changes - 16/Feb/11 12:08 PM
Component/s cdi [ 10637 ]
Hong Zhang added a comment - 16/Feb/11 12:12 PM

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


Hong Zhang made changes - 16/Feb/11 12:12 PM
Assignee Hong Zhang [ hzhang_jn ] Sivakumar Thyagarajan [ sivakumart ]
Component/s deployment [ 10594 ]
Jill Sato made changes - 02/Dec/11 07:25 PM
Fix Version/s 4.0 [ 10970 ]
Fix Version/s 3.2 [ 10969 ]
jjsnyder83 made changes - 15/Oct/12 02:25 PM
Tags 3_1-exclude 3_1-exclude req-weld-fix
jjsnyder83 added a comment - 15/Oct/12 02:25 PM

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


jjsnyder83 made changes - 15/Oct/12 02:26 PM
Assignee Sivakumar Thyagarajan [ sivakumart ] jjsnyder83 [ jjsnyder83 ]
phil.zampino added a comment - 19/Mar/13 09:12 PM

This was resolved by Weld.


phil.zampino made changes - 19/Mar/13 09:12 PM
Status Open [ 1 ] Closed [ 6 ]
Resolution Fixed [ 1 ]