[cdi-dev] [JBoss JIRA] (CDI-490) Clarify what happens when an interceptor/decorator is enabled using both @Priority and beans.xml

Martin Kouba (JIRA) issues at jboss.org
Wed Nov 5 03:40:35 EST 2014

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

Martin Kouba commented on CDI-490:

For options 2) and 3) there should be also a big warning about the fact, that the ordering may be different on CDI 1.0 and CDI 1.1+. 

For option 2), consider the following beans.xml:
and interceptor classes:
class TransactionInterceptor {}

class LoggingInterceptor {}
The ordering would be:
* CDI 1.0
## TransactionInterceptor
## LoggingInterceptor
* CDI 1.1+
## LoggingInterceptor
## TransactionInterceptor

To fix this a user would either have to add {{@Priority}} to relevant interceptor classes or modify {{javax.enterprise.inject.spi.AfterTypeDiscovery.getInterceptors()}}.

> Clarify what happens when an interceptor/decorator is enabled using both @Priority and beans.xml
> ------------------------------------------------------------------------------------------------
>                 Key: CDI-490
>                 URL: https://issues.jboss.org/browse/CDI-490
>             Project: CDI Specification Issues
>          Issue Type: Clarification
>          Components: Decorators, Interceptors
>    Affects Versions: 1.2.Final
>            Reporter: Jozef Hartinger
> Suppose an InterceptorA has @Priority and is also listed in the beans.xml file of a particular BDA. Such interceptor is for sure enabled because:
> {quote}An interceptor is said to be enabled if it is enabled in at least one bean archive or is listed in the final
> list of interceptors for the application, as defined in Section 11.5.2, “AfterTypeDiscovery event”.{quote}
> it matches both parts of the statement.
> As for ordering, the following statement defines invocation order:
> {quote}Interceptors enabled using @Priority are called before interceptors enabled using beans.xml.{quote}
> Since InterceptorA is enabled by both @Priority and beans.xml, the following applies:
> "Interceptors enabled using @Priority" = \{ InterceptorA \}
> "interceptors enabled using beans.xml" = \{ InterceptorA \}
> We can perform substitution in the statement and we get:
> *\{ InterceptorA \} are called before \{ InterceptorA \}*
> which does not seem right.
> The specification should explicitly address this scenario. There are several options (some of them are better, some are worse):
> 1) Invoke the interceptor twice - each time in the corresponding order given by priority and position in beans.xml
> 2) Invoke the interceptor once in the @Priority part of the invocation chain (@Priority has precedence)
> 3) Invoke the interceptor once in the beans.xml part of the invocation chain (beans.xml has precedence)
> 4) Forbid an interceptor to be enabled by both @Priority and beans.xml

This message was sent by Atlassian JIRA

More information about the cdi-dev mailing list