Uploaded image for project: 'CDI Specification Issues'
  1. CDI Specification Issues
  2. CDI-479

How to identify the bean a static observer method belongs to

    XMLWordPrintable

Details

    • Clarification
    • Resolution: Obsolete
    • Major
    • None
    • None
    • None
    • None

    Description

      Let's sum up some parts of the spec which are relevant to static observer methods:
      "10.4. Observer methods":

      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.

      "10.3. Observer resolution":

      An event is delivered to an observer method if:

      • The observer method belongs to an enabled bean.
      • ...

      "12.4.3. Bean discovery":

      For each observer method of every enabled bean, the container registers an instance of the ObserverMethod interface defined in The ObserverMethod interface.

      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:

      Static observer method on an abstract class

      public abstract class Foo {
        public static observe1(@Observes Event1 event1) {
        }
      }
      public class Bar extends Foo {
      }
      

      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?

      Specialization

      public class Foo {
        public static observe1(@Observes Event2 event2) {
        }
      }
      @Specializes
      public class Bar extends Foo {
      }
      

      Foo is specialized by Bar and thus it's disabled. Is the observer method detected? Does it belong to Bar?

      Attachments

        Activity

          People

            Unassigned Unassigned
            mkouba@redhat.com Martin Kouba
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: