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

Weld SE throws NPE when trying to intercept a method called by constructor

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 3.0.4.Final, 2.4.8.Final
    • 3.0.3.Final
    • None
    • None
    • Hide
      1. Create a class calling one of it's methods from the constructor.
      2. Create an interceptor intercepting the execution of that method.
      3. Try to get an instance of the class from Weld-SeContainer.

      A simple project showcasing the issue is attached. Just start the main-Method in demo.DemoClass. If you remove the @Logged annotation on demo.DemoClass.init() it works.

      Show
      Create a class calling one of it's methods from the constructor. Create an interceptor intercepting the execution of that method. Try to get an instance of the class from Weld-SeContainer. A simple project showcasing the issue is attached. Just start the main-Method in demo.DemoClass . If you remove the @Logged annotation on demo.DemoClass.init() it works.
    • Workaround Exists
    • Hide

      Disable relaxed construction, .e.g. run your app with -Dorg.jboss.weld.construction.relaxed=false. See also http://docs.jboss.org/weld/reference/latest-master/en-US/html/configure.html#relaxedConstruction.

      Show
      Disable relaxed construction, .e.g. run your app with -Dorg.jboss.weld.construction.relaxed=false . See also http://docs.jboss.org/weld/reference/latest-master/en-US/html/configure.html#relaxedConstruction .

    Description

      I tried to use an interceptor on a method called by a class constructor. This results in a NullPointerException on the Proxy-Object of the respective object.

      Exception in thread "main" java.lang.NullPointerException
          at demo.DemoClass$Proxy$_$$_WeldSubclass.init(Unknown Source)
          at demo.DemoClass.<init>(DemoClass.java:15)
          at demo.DemoClass$Proxy$_$$_WeldSubclass.<init>(Unknown Source)
          at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
          at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
          at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
          at java.lang.reflect.Constructor.newInstance(Unknown Source)
          at org.jboss.weld.injection.ConstructorInjectionPoint.newInstance(ConstructorInjectionPoint.java:119)
          at org.jboss.weld.injection.ProxyClassConstructorInjectionPointWrapper.newInstance(ProxyClassConstructorInjectionPointWrapper.java:83)
          at org.jboss.weld.injection.ConstructorInjectionPoint.invokeAroundConstructCallbacks(ConstructorInjectionPoint.java:92)
          at org.jboss.weld.injection.ConstructorInjectionPoint.newInstance(ConstructorInjectionPoint.java:78)
          at org.jboss.weld.injection.producer.AbstractInstantiator.newInstance(AbstractInstantiator.java:28)
          at org.jboss.weld.injection.producer.InterceptorApplyingInstantiator.newInstance(InterceptorApplyingInstantiator.java:62)
          at org.jboss.weld.injection.producer.BasicInjectionTarget.produce(BasicInjectionTarget.java:112)
          at org.jboss.weld.injection.producer.BeanInjectionTarget.produce(BeanInjectionTarget.java:186)
          at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:158)
          at org.jboss.weld.contexts.unbound.DependentContextImpl.get(DependentContextImpl.java:70)
          at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:100)
          at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)
          at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:689)
          at org.jboss.weld.bean.builtin.InstanceImpl.getBeanInstance(InstanceImpl.java:252)
          at org.jboss.weld.bean.builtin.InstanceImpl.get(InstanceImpl.java:114)
          at demo.DemoClass.main(DemoClass.java:34)
      

      Attachments

        Issue Links

          Activity

            People

              mkouba@redhat.com Martin Kouba
              alanz26 Andreas Lanz (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: