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

Tomas Remes (JIRA) issues at jboss.org
Fri Mar 11 01:47:00 EST 2016


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

Tomas Remes commented on CDI-479:
---------------------------------

I've found this. 
# We have {{org.jboss.cdi.tck.tests.event.broken.observer.beanNotManaged.ObserverMethodOnIncorrectBeanTest}} where we check that observer is disabled (not resolved) at non-managed bean and at abstract class with abstract method observer which is overriden in extending class.
# We have {{org.jboss.cdi.tck.tests.event.observer.ObserverNotificationTest#testObserversNotified}} where we check that observer is disabled at bean which is not selected alternative.

I think we can expand both cases in TCK and probably close this issue. What do you think [~antoinesabot-durand]?

> 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