-
Feature Request
-
Resolution: Unresolved
-
Minor
-
2.2.5.Final
-
None
-
None
Given:
@Named @RequestScoped public class TestController { @Inject private Event<String> event; @PostConstruct void init() { event.fire("hello"); } void onEvent(@Observes String event) { System.out.println(event); } public void test() { event.fire("world"); } }
Initializing a TestController e.g. by invoking TestController.test() or reference some of it's properties will cause:
java.lang.StackOverflowError at org.jboss.weld.injection.FieldInjectionPoint.delegate(FieldInjectionPoint.java:104) at org.jboss.weld.injection.FieldInjectionPoint.delegate(FieldInjectionPoint.java:44) at org.jboss.weld.injection.ForwardingInjectionPoint.getType(ForwardingInjectionPoint.java:22) at org.jboss.weld.manager.BeanManagerImpl.isRegisterableInjectionPoint(BeanManagerImpl.java:1453) at org.jboss.weld.manager.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:791) at org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:92) at org.jboss.weld.util.Beans.injectBoundFields(Beans.java:375) at org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:386) at org.jboss.weld.injection.producer.ResourceInjector$1.proceed(ResourceInjector.java:70) at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:48) at org.jboss.weld.injection.producer.ResourceInjector.inject(ResourceInjector.java:65) at org.jboss.weld.injection.producer.BasicInjectionTarget.inject(BasicInjectionTarget.java:121) at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:150) at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:96) at org.jboss.weld.event.ObserverMethodImpl.getReceiver(ObserverMethodImpl.java:307) at org.jboss.weld.event.ObserverMethodImpl.getReceiverIfExists(ObserverMethodImpl.java:292) at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:256) at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:237) at org.jboss.weld.event.ObserverNotifier.notifyObserver(ObserverNotifier.java:174) at org.jboss.weld.event.ObserverNotifier.notifyObserver(ObserverNotifier.java:170) at org.jboss.weld.event.ObserverNotifier.notifyObservers(ObserverNotifier.java:124) at org.jboss.weld.event.EventImpl.fire(EventImpl.java:84) at kn.gvs.shipmentoperating.dashboard.ui.controller.TestController.init(TestController.java:19) at sun.reflect.GeneratedMethodAccessor277.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.invokeMethods(DefaultLifecycleCallbackInvoker.java:98) at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.postConstruct(DefaultLifecycleCallbackInvoker.java:81) at org.jboss.weld.injection.producer.BasicInjectionTarget.postConstruct(BasicInjectionTarget.java:126) at org.jboss.weld.injection.producer.BeanInjectionTarget.postConstruct(BeanInjectionTarget.java:70) at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:153) at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:96) at org.jboss.weld.event.ObserverMethodImpl.getReceiver(ObserverMethodImpl.java:307) at org.jboss.weld.event.ObserverMethodImpl.getReceiverIfExists(ObserverMethodImpl.java:292) at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:256) at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:237) at org.jboss.weld.event.ObserverNotifier.notifyObserver(ObserverNotifier.java:174) at org.jboss.weld.event.ObserverNotifier.notifyObserver(ObserverNotifier.java:170) at org.jboss.weld.event.ObserverNotifier.notifyObservers(ObserverNotifier.java:124) at org.jboss.weld.event.EventImpl.fire(EventImpl.java:84) at kn.gvs.shipmentoperating.dashboard.ui.controller.TestController.init(TestController.java:19) at sun.reflect.GeneratedMethodAccessor277.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.invokeMethods(DefaultLifecycleCallbackInvoker.java:98) at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.postConstruct(DefaultLifecycleCallbackInvoker.java:81) at org.jboss.weld.injection.producer.BasicInjectionTarget.postConstruct(BasicInjectionTarget.java:126) at org.jboss.weld.injection.producer.BeanInjectionTarget.postConstruct(BeanInjectionTarget.java:70) at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:153) at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:96) at org.jboss.weld.event.ObserverMethodImpl.getReceiver(ObserverMethodImpl.java:307) at org.jboss.weld.event.ObserverMethodImpl.getReceiverIfExists(ObserverMethodImpl.java:292) at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:256) at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:237) at org.jboss.weld.event.ObserverNotifier.notifyObserver(ObserverNotifier.java:174) at org.jboss.weld.event.ObserverNotifier.notifyObserver(ObserverNotifier.java:170) at org.jboss.weld.event.ObserverNotifier.notifyObservers(ObserverNotifier.java:124) at org.jboss.weld.event.EventImpl.fire(EventImpl.java:84) at kn.gvs.shipmentoperating.dashboard.ui.controller.TestController.init(TestController.java:19) [...]
I assume beans not having finished their initialization lifecycle won't be available via their context, so any invocation of these beans will lead to the creation of another one. The CDI spec is unfortunately rather vague on availability of beans during creation.
I am using CDI events to break up circular dependencies between beans.Unfortunately I am not able to invoke anything from @PostConstruct initializers,if the invocation is directly (e.g. via method call on dependent bean) or indirectly (e.g. via eventing) calling the bean in in creation back.