A (valid) CDI producer method like this:
@Produces public Integer fortyTwo() { return Integer.valueOf(42); }
…is not observed by a (valid) portable extension's container lifecycle event observer method that looks like this:
private final void processBean(@Observes final ProcessBean<Integer> event) { /* ?! */ }
...or this:
private final void processBean(@Observes final ProcessBean<? extends Number> event) { /* ?! */ }
...or this (not surprisingly):
private final void processBean(@Observes final ProcessBean<Object> event) { /* obviously */ }
...but is observed by one that looks like this:
private final void processBean(@Observes final ProcessBean<?> event) { /*...*/ }
…and the toString() output of event.getBean().getTypes() at that point is:
[class java.lang.Number, class java.lang.Integer, interface java.io.Serializable, class java.lang.Object, java.lang.Comparable<java.lang.Integer>]
The specification says that "The event object type in the package javax.enterprise.inject.spi depends upon what kind of bean was discovered". It says in particular that "[f]or a producer method with method return type T of a bean with bean class X, the container must raise an event of type ProcessProducerMethod<T, X>." Then it lists some other concrete event types which seemingly should cover all bases.
Nevertheless, there is still this ProcessBean interface, which is public (they could have made it an implementation detail of the concrete events detailed by the specification, and hence "off-limits"), so it would seem it was intended that this should be observable directly. Unfortunately, as noted, the only way I've found to write a container lifecycle event observer method that does observe ProcessBean is to observe ProcessBean<?> and none other.
I find this all very surprising. Is this pilot error or a bug in Weld (the CDI implementation I'm using)? What should I do if I want to be notified of every bean of a given type, regardless of whether it's a managed bean, session bean, synthetic bean, producer method or producer field?