Uploaded image for project: 'Weld'
  1. Weld
  2. WELD-2461

ProcessBean observer method not notified of producer method beans

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Do
    • Major
    • None
    • 3.0.2.Final
    • Events, Extensions
    • None
    • Hide
      1. Write a producer method that returns Integer.
      2. Write a container lifecycle event observer that observes ProcessBean<Integer>. Note that it is never called.
      3. Write a container lifecycle event observer that observes ProcessBean<?>. Note that in this case it is called.
      Show
      Write a producer method that returns Integer . Write a container lifecycle event observer that observes ProcessBean<Integer> . Note that it is never called. Write a container lifecycle event observer that observes ProcessBean<?> . Note that in this case it is called.

    Description

      (I've posted a summary on StackOverflow.)

      In short, it is my understanding that a (valid) producer method returning type X is a bean whose bean types include X and should therefore be observable by a container lifecycle event observer method of the form:

      private final void processBean(@Observes final ProcessBean<X> event) {/*...*/}
      

      …in addition to being observable by an observer of the ProcessProducerMethod event type.

      But in fact it seems to me that the only way an observer of ProcessBean events can get notified of producer methods (a valid kind of bean) is to observe the unbounded wildcard or an equivalent construct, e.g.

      private final void processBean(@Observes final ProcessBean<?> event) {/*...*/}
      

      (I'm obviously aware that I could define an observer method that observes ProcessProducerMethod events, but I am specifically interested in observing all beans, producers or not, of a particular type.)

      I am not sure of the culprit, but after debugging into Weld's innards I found that it looks to my naïve eyes like at some point the type parameters got reversed when Weld builds a ProcessProducerMethod event to fire, but perhaps only in certain cases since observing a ProcessProducerMethod directly works fine.

      That is, ProcessBean<X>'s actual type parameter value gets "put" into the T "slot" of ProcessProducerMethod<T, X> when Weld is preparing to notify my general-purpose ProcessBean observer method. Here is the string/debugger output of a Resolvable passed in to TypeSafeResolver#resolve() during the execution of ObserverNotifier#resolveObserverMethods():

      Types: [interface javax.enterprise.inject.spi.ProcessBean<class com.foo.HostBean>, interface javax.enterprise.inject.spi.ProcessProducerMethod<class java.lang.Integer,class com.foo.HostBean>, class java.lang.Object]; Bindings: [QualifierInstance {annotationClass=interface javax.enterprise.inject.Any, values={}}]
      

      It is my understanding from the CDI specification that this should be a ProcessBean<Integer> and a ProcessProducerMethod<Integer, HostBean>, but instead it is a ProcessBean<HostBean> and a ProcessProducerMethod<Integer, HostBean>.

      At any rate, I'm unfamiliar with this area of the codebase and may have analyzed it wrongly. My apologies if this is an invalid bug report.

      Attachments

        Activity

          People

            Unassigned Unassigned
            ljnelson+github@gmail.com Laird Nelson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: