-
1. Re: Does a Producer/InjectionTarget’s dispose() method get called for managed beans?
manovotn Apr 25, 2019 4:18 AM (in response to ljnelson)I wouldn't say you miss anything.
But if the spec says that dispose() does nothing in that particular case, it doesn't imply that it has to be called.
Maybe predestroy callback would work better here?
-
2. Re: Does a Producer/InjectionTarget’s dispose() method get called for managed beans?
ljnelson Apr 25, 2019 1:09 PM (in response to manovotn)manovotn wrote:
> I wouldn't say you miss anything.
> But if the spec says that dispose() does nothing in that particular case, it doesn't imply that it has to be called.
I gently disagree. I would expect that the default InjectionTarget/Producer's dispose() method would be called, it just wouldn't do anything.
I'll put together a test case. As I mentioned, I'm simply replacing the default InjectionTarget during ProcessInjectionTarget with one that prints something during its destroy() invocation before calling super.destroy(). My injection target's dispose() method is never called. I feel that it must be according to section 11.2 (http://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#injectiontarget).
I'll try the preDestroy() override; maybe that will work. Thanks for your help!
-
3. Re: Does a Producer/InjectionTarget’s dispose() method get called for managed beans?
ljnelson Apr 25, 2019 1:00 PM (in response to ljnelson)Aha; I see that Weld's ManagedBean implementation does not call dispose() but does call preDestroy(): https://github.com/weld/core/blob/6c2b09fac4e694a20877f017424acd6c4b3e3439/impl/src/main/java/org/jboss/weld/bean/ManagedBean.java#L188-L203
I will think some more about this, but at the moment I feel that this is a bug. I could see that if Weld determines that no one has supplied a different Producer that it wouldn't have to do anything, but if a portable extension does supply a Producer then it seems that its dispose() method must be called.
-
4. Re: Does a Producer/InjectionTarget’s dispose() method get called for managed beans?
ljnelson Apr 25, 2019 1:44 PM (in response to ljnelson)https://issues.jboss.org/browse/WELD-2580 filed with test case and pull request.
-
5. Re: Does a Producer/InjectionTarget’s dispose() method get called for managed beans?
ljnelson Apr 25, 2019 1:54 PM (in response to manovotn)manovotn wrote:
I wouldn't say you miss anything.
But if the spec says that dispose() does nothing in that particular case, it doesn't imply that it has to be called.
Here's my problem (took me a while to nail this down):
- If ProcessInjectionTarget is fired only for managed beans, and
- it is possible to set your own InjectionTarget on that event to replace the original one, and
- it is legal for a CDI implementation to not call dispose() for managed beans, then
- why does InjectionTarget define a dispose() method?
I expect that (3) is false.
-
6. Re: Does a Producer/InjectionTarget’s dispose() method get called for managed beans?
mkouba Apr 26, 2019 3:11 AM (in response to ljnelson)So the spec is not really clear and does not cover this corner case properly. It is true that an extension could replace the original InjectionTarget for any bean, however if you do so you're "entering a dangerous zone" and you should be very careful. Even a small change could result in unpredictable behavior. WRT
dispose()
- I think that the original intent was to provide a way for producers to simulate the@PreDestroy
callback because obvisouly that's something you can't do with producer methods and fields. For class beans it's redundant. That being said, it's a small change that "SHOULD NOT" affect any existing apps. Well, I rember I said a similar sentence many times and surprisingly often another corner case proved the opposite.In any case, if you need to wrap the original
InjectionTarget
and to do some cleanup it should be safe to perform the action withinInjectionTarget.preDestroy()
.