[cdi-dev] [JBoss JIRA] (CDI-479) How to identify the bean a static observer method belongs to

Martin Kouba (JIRA) issues at jboss.org
Thu Mar 10 15:02:00 EST 2016


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

Martin Kouba commented on CDI-479:
----------------------------------

Ok, so I've read the spec again and I also think both the observer methods from examples should be ignored because:
1. in example one it's not a method of a managed bean class
2. in example two the method does not belong to an enabled bean

On the other hand, it might confusing for users as they might expect them to work. I suppose we don't have a TCK test for this, do we?

> How to identify the bean a static observer method belongs to
> ------------------------------------------------------------
>
>                 Key: CDI-479
>                 URL: https://issues.jboss.org/browse/CDI-479
>             Project: CDI Specification Issues
>          Issue Type: Clarification
>            Reporter: Martin Kouba
>
> Let's sum up some parts of the spec which are relevant to static observer methods:
> "10.4. Observer methods":
> {quote}
> An observer method is a non-abstract method of a managed bean class or session bean class...
> An observer method may be either static or non-static.
> {quote}
> "10.3. Observer resolution":
> {quote}
> An event is delivered to an observer method if:
> * The observer method belongs to an enabled bean.
> * ...
> {quote}
> "12.4.3. Bean discovery":
> {quote}
> For each observer method of every enabled bean, the container registers an instance of the ObserverMethod interface defined in The ObserverMethod interface.
> {quote}
> Now what is the algorithm to *identify the bean a static observer method belongs to*? Is is bound to all beans whose Bean.getBeanClass() declares the method? There are two special scenarios I have in mind:
> h3. Static observer method on an abstract class
> {code:java}
> public abstract class Foo {
>   public static observe1(@Observes Event1 event1) {
>   }
> }
> public class Bar extends Foo {
> }
> {code}
> Foo is not a bean. Foo.observe1() is not a method of managed bean class Bar (if we strictly follow the JSL). Is the observer method detected? Does it belong to Bar? What if there are several subclasses of Foo?
> h3. Specialization
> {code:java}
> public class Foo {
>   public static observe1(@Observes Event2 event2) {
>   }
> }
> @Specializes
> public class Bar extends Foo {
> }
> {code}
> Foo is specialized by Bar and thus it's disabled. Is the observer method detected? Does it belong to Bar? 



--
This message was sent by Atlassian JIRA
(v6.4.11#64026)


More information about the cdi-dev mailing list