[cdi-dev] [JBoss JIRA] (CDI-581) possible chicken-egg problem with ProcessBeanAttributes#veto and specialization

Mark Struberg (JIRA) issues at jboss.org
Fri Feb 12 05:51:00 EST 2016

    [ https://issues.jboss.org/browse/CDI-581?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13162128#comment-13162128 ] 

Mark Struberg commented on CDI-581:

Thanks Martin. I also think that this solution will get 'close' but will not hit 100%. The question now is if we are happy with a 'somehow close' solution or we like to nail it down 100%?
In my personal opinion it's much preferable to have a clear rule and the processing is always strictly unidirectional and acyclic. 

With having those 'cycles' in the processing we get 2 imo undesired results:
1.) It's pretty much almost unpredictable for a random joe user what will happen. That's imo a big drawback
2.) We the rest of the cases which isn't solved by the complex cycling will end up being non-deterministic. Thus having an app which will work at one boot but fail (or just have a different behaviour) on another boot.

I really prefer to always send the ProcessBeanAttributes for all non-vetoed AnnotatedTypes and then have a clear sheet to determine which Bean<?> are not enabled and thus could get skipped. A PBA event for a later disabled bean is imo way better than missing a PBA event for a bean which is finally valid and in production.

> possible chicken-egg problem with ProcessBeanAttributes#veto and specialization
> -------------------------------------------------------------------------------
>                 Key: CDI-581
>                 URL: https://issues.jboss.org/browse/CDI-581
>             Project: CDI Specification Issues
>          Issue Type: Bug
>    Affects Versions: 1.2.Final
>            Reporter: Mark Struberg
> Currently section 12 describes that ProcessBeanAttributes only should get fired for 'enabed beans'. 
> {quote}
> 12.4.3. Bean discovery
> * if the class is an enabled bean, interceptor or decorator, fire an event of type ProcessBeanAttributes, as defined in ProcessBeanAttributes event,
> {quote}
> But if you have class B extends A and B is @Specializes then you don't know which PBA to fire. Because B could get vetoed in ProcessBeanAttributes. And then while you fire PBA you implicitly change the list of enabled beans. This gets even more complicated by the ability of ProcessBeanAttributes to change the isAlternative bit and even the types of the whole bean. 
> I think this might be a left-over of the split between Bean and BeanAttributes. The ProcessBeanAttributes is right in the middle between ProcessAnnotatedType and ProcessBean. 
> * ProcessBean die _not_ have a veto(), PAT does have it. 
> * PAT gets fired for all discovered classes, ProcessBean only for enabled ones.
> I think the wording 'if the class is an enabled *bean*' is also misleading. We do _not_ have a bean at this early stage! We only have an AnnotatedType. Maybe it should read ''if the class is a not vetoed AnnotatedType'?
> I'm not sure if there is a way the current wording could get cleanly implemented. I just stumbled across this because we did _not_ fire a PBA for a class because the @Specialized bean got vetoed away.
> The same chicken-egg problem might apply to
> {quote}
> 11.5.9. ProcessBeanAttributes event
> The container must fire an event for each bean, interceptor or decorator deployed in a bean
> archive, before registering the Bean object."
> {quote}
> Reads "for every bean". But we don't have any beans yet. We can only make the Bean<T> after the BeanAttributes get returned from PBA. Otherwise changing the bean attributes would have no effect on the Bean, right?
> What could work is roughly:
> * fire PAT for all detected classes
> * remove vetoed ones
> * fire PBA for all AnnotatedTypes
> * remove vetoed one
> * calculate disabled BeanAttributes (@Specializes rule for classes)
> * produce Beans

This message was sent by Atlassian JIRA

More information about the cdi-dev mailing list