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

Injectable constructor ignored when decorators are enabled

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Critical Critical
    • 2.0.4.Final, 2.1.0.Alpha1
    • 1.1.13.Final, 2.0.1.Final
    • None
    • None

      I have a chain of decorators for a managed bean.

      If they are enabled, the container tries to proxy the managed bean, although it uses the default @Dependent scope. When creating the proxy, it ignores the injected constructor with parameters and tries to use the default constructor with no parameters instead. As a result, this fails with an InstantiationException:

      Exception in thread "main" org.jboss.weld.exceptions.WeldException: WELD-000033 Could not instantiate client proxy for org.jboss.weld.bean.proxy.DecorationHelper@62fa5ff3
      	at org.jboss.weld.bean.proxy.DecorationHelper.createProxy(DecorationHelper.java:118)
      	at org.jboss.weld.bean.proxy.DecorationHelper.getNextDelegate(DecorationHelper.java:101)
      	at org.jboss.weld.injection.producer.AbstractDecoratorApplyingInstantiator.getOuterDelegate(AbstractDecoratorApplyingInstantiator.java:75)
      	at org.jboss.weld.injection.producer.SubclassDecoratorApplyingInstantiator.applyDecorators(SubclassDecoratorApplyingInstantiator.java:45)
      	at org.jboss.weld.injection.producer.AbstractDecoratorApplyingInstantiator.newInstance(AbstractDecoratorApplyingInstantiator.java:65)
      	at org.jboss.weld.injection.producer.BasicInjectionTarget.produce(BasicInjectionTarget.java:86)
      	at org.jboss.weld.injection.producer.BeanInjectionTarget.produce(BeanInjectionTarget.java:173)
      	at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:157)
      	at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:69)
      	at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:718)
      	at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:774)
      	at org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:92)
      	at org.jboss.weld.util.Beans.injectBoundFields(Beans.java:372)
      	at org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:381)
      	at org.jboss.weld.injection.producer.DefaultInjector.inject(DefaultInjector.java:72)
      	at org.jboss.weld.injection.producer.ResourceInjector.inject(ResourceInjector.java:60)
      	at org.jboss.weld.injection.producer.DefaultInjector$1.proceed(DefaultInjector.java:66)
      	at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:48)
      	at org.jboss.weld.injection.producer.DefaultInjector.inject(DefaultInjector.java:64)
      	at org.jboss.weld.injection.producer.BasicInjectionTarget.inject(BasicInjectionTarget.java:91)
      	at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:158)
      	at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:103)
      	at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:718)
      	at org.jboss.weld.event.ObserverMethodImpl.getReceiver(ObserverMethodImpl.java:302)
      	at org.jboss.weld.event.ObserverMethodImpl.getReceiverIfExists(ObserverMethodImpl.java:295)
      	at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:259)
      	at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:240)
      	at org.jboss.weld.event.ObserverNotifier.notifyObserver(ObserverNotifier.java:171)
      	at org.jboss.weld.event.ObserverNotifier.notifyObserver(ObserverNotifier.java:167)
      	at org.jboss.weld.event.ObserverNotifier.notifyObservers(ObserverNotifier.java:121)
      	at org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:114)
      	at org.jboss.weld.event.EventImpl.fire(EventImpl.java:84)
      	at org.jboss.weld.environment.se.Weld.initialize(Weld.java:153)
      	at org.jboss.weld.environment.se.StartMain.go(StartMain.java:41)
      	at org.jboss.weld.environment.se.StartMain.main(StartMain.java:52)
      Caused by: java.lang.InstantiationException: com.company.mavenproject1.StandardPrinter$Proxy$_$$_Weld$Proxy$
      	at java.lang.Class.newInstance0(Class.java:342)
      	at java.lang.Class.newInstance(Class.java:310)
      	at org.jboss.weld.security.NewInstanceAction.run(NewInstanceAction.java:33)
      	at java.security.AccessController.doPrivileged(Native Method)
      	at org.jboss.weld.bean.proxy.DecorationHelper.createProxy(DecorationHelper.java:109)
      	... 34 more
      

      If I disable the chain of decorators or refactor the managed bean to use a private @Inject field, then the example works as designed.

      I assess this as a critical bug because I don't want to rely on private field injection.

      I have attached a ZIP file with the sample code.

              maxmil_jira Max Pimm (Inactive)
              christians_jira Christian Schlichtherle (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: