8 Replies Latest reply on Sep 18, 2010 7:08 PM by Marcel Kolsteren

    Intercepting beans created by weld-se using constructor based injection

    Richard Hauswald Newbie
      Hi,
      my name is Richard, I'm pretty new to weld and currently trying to write a weld-se builder to make testing easy. I'm currently testing the stuff. Injection works fine but I noticed a problem while testing interception: If I try to intercept a bean that is created using a @Inject annotated constructor with multiple arguments I get the following Exception:
      org.jboss.weld.exceptions.DeploymentException: de.rhauswald.weld.test.mock.org$jboss$weld$bean-classpath-ManagedBean-class_de$rhauswald$weld$test$mock$ConstructorBasedInjectionService_$$_WeldProxy
           at org.jboss.weld.bean.ManagedBean.applyInterceptors(ManagedBean.java:600)
           at org.jboss.weld.bean.ManagedBean$ManagedBeanInjectionTarget.produce(ManagedBean.java:256)
           at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:338)
           at org.jboss.weld.context.DependentContext.get(DependentContext.java:62)
           at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:660)
           at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:698)
           at org.jboss.weld.bean.builtin.InstanceImpl.get(InstanceImpl.java:79)
           at de.rhauswald.weld.test.TestWeldInterceptorTest.produce(TestWeldInterceptorTest.java:75)
           at de.rhauswald.weld.test.TestWeldInterceptorTest.testTestWeldInterceptsConstructorInjectedService(TestWeldInterceptorTest.java:47)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:597)
           at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
           at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
           at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
           at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
           at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
           at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
           at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
           at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
           at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
           at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
           at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
           at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
           at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
           at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
           at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
           at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
           at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
           at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
      Caused by: org.jboss.weld.exceptions.DefinitionException: de.rhauswald.weld.test.mock.org$jboss$weld$bean-classpath-ManagedBean-class_de$rhauswald$weld$test$mock$ConstructorBasedInjectionService_$$_WeldProxy
           at org.jboss.weld.bean.proxy.ProxyFactory.create(ProxyFactory.java:223)
           at org.jboss.weld.bean.ManagedBean.applyInterceptors(ManagedBean.java:594)
           ... 30 more
      Caused by: java.lang.InstantiationException: de.rhauswald.weld.test.mock.org$jboss$weld$bean-classpath-ManagedBean-class_de$rhauswald$weld$test$mock$ConstructorBasedInjectionService_$$_WeldProxy
           at java.lang.Class.newInstance0(Class.java:340)
           at java.lang.Class.newInstance(Class.java:308)
           at org.jboss.weld.util.reflection.SecureReflections$16.work(SecureReflections.java:396)
           at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:54)
           at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInstantiation(SecureReflectionAccess.java:216)
           at org.jboss.weld.util.reflection.SecureReflections.newInstance(SecureReflections.java:391)
           at org.jboss.weld.bean.proxy.ProxyFactory.create(ProxyFactory.java:218)
           ... 31 more

      This is not the case if I intercept a bean with a default constructor using field based injection. Is this a bug, a feature or did I made a mistake?

      Thanks,
      Richard