[cdi-dev] Possible cycle with ProcessBeanAttributes only for enabled beans
struberg at yahoo.de
Mon Dec 22 12:58:47 EST 2014
The JavaDoc of ProcessBeanAttributes defines that ProcessBeanAttributes must only get fired for ENABLED beans:
"The container fires an event of this type for each enabled bean, interceptor or decorator deployed in a bean archive before registering the Bean object."
has a nice example
@Specializes class Charly extends
-> @Specializes class Bravo extends
-> class Alpha
Which ProcessBeanAttributes events would you except to get fired?
*) Alpha? No, because it's specialized away (5.1.2. Enabled and disabled beans).
*) Bravo? No, because it's specialized away as well, right?
*) Charly? Yes, because that's the only _enabled_ bean!
So far, so clear. But now comes the tricky part!
This test also has an Extension which observes ProcessBeanAttributes and disables Charly.
This means that finally Bravo is enabled, Charly disabled (is there actually a difference btw disabled and vetoed spec wording wise?)
The problem is now that we only know this AFTER the ProcessBeanAttributes for Charly got fired. And this introduces an ordering issue:
If the BeanAttributes for Bravo gets scanned BEFORE the ones of Charly, then we do not know YET that Charly will get disabled. Thus we fire the ProcessBeanAttributes for Bravo as well. But as we know that should not happen!
Otoh if Charly gets scanned first, then Bravo will not get processed.
Can you follow me?
More information about the cdi-dev