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

NPE Abortion - CDI-Bean / Inheritance / Generics / Interceptor

    XMLWordPrintable

    Details

      Description

      The following constellation leads to an NPE-Exception which aborts the startup process:

      • A CDI-Bean inherits from an generic abstract class and
      • overwrites their abstract method.
      • The abstract method must return a typeparameter.
      • The method of the CDI-Bean must have an InterceptorBinding-Annotation

      Code-Snippets (full Implementation can be found in the Example.zip)

       
      @ApplicationScoped
      public class CarRepairer extends Repairer<Car> {
       
          @Override
          // Without the transactional annotation the bean would be loaded.
          @Transactional
          public Car repair() {
              return new Car();
          }
      }
       
      // Without generic, the bean would be loaded
      public abstract class Repairer<T> {
       
          // If this method would not be abstract, everything would be fine
          public abstract T repair();
       
      }
      

      Code-Snippets using generic inheritance(full Implementation can be found in the GenericInheritance.zip)

       
      @ApplicationScoped
      public class CarRepairer extends Repairer<Car> {
       
          @Override
          // Without the transactional annotation the bean would be loaded.
          @Transactional
          public Car repair() {
              return new Car();
          }
      }
       
      // Without generic, the bean would be loaded
      // Pullrequest https://github.com/weld/core/pull/1801
      // does not help if generic inherits from another class.
      public abstract class Repairer<T extends Vehicle> {
       
          // If this method would not be abstract, everything would be fine
          public abstract T repair();
       
      }
      

      Exception:

      Caused by: org.jboss.weld.exceptions.WeldException: WELD-001524: Unable to load proxy class for bean Managed Bean [class weldtest.CarRepairer] with qualifiers [@Any @Default] with class class weldtest.CarRepairer using classloader WebappClassLoader
        context: app#tcorder
        delegate: false
      	at org.jboss.weld.bean.proxy.ProxyFactory.getProxyClass(ProxyFactory.java:398)
      	at org.jboss.weld.injection.producer.SubclassedComponentInstantiator.createEnhancedSubclass(SubclassedComponentInstantiator.java:113)
      	at org.jboss.weld.injection.producer.SubclassedComponentInstantiator.initEnhancedSubclass(SubclassedComponentInstantiator.java:86)
      	at org.jboss.weld.injection.producer.SubclassedComponentInstantiator.<init>(SubclassedComponentInstantiator.java:79)
      	at org.jboss.weld.injection.producer.SubclassedComponentInstantiator.forInterceptedDecoratedBean(SubclassedComponentInstantiator.java:63)
      	at org.jboss.weld.injection.producer.BeanInjectionTarget.initializeAfterBeanDiscovery(BeanInjectionTarget.java:121)
      	at org.jboss.weld.injection.producer.InjectionTargetInitializationContext.initialize(InjectionTargetInitializationContext.java:42)
      	at org.jboss.weld.injection.producer.InjectionTargetService.initialize(InjectionTargetService.java:63)
      	at org.jboss.weld.bootstrap.WeldStartup.deployBeans(WeldStartup.java:465)
      	at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:83)
      	at org.jboss.weld.environment.servlet.WeldServletLifecycle.initialize(WeldServletLifecycle.java:236)
      	at org.jboss.weld.environment.servlet.EnhancedListener.onStartup(EnhancedListener.java:62)
      	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5302)
      	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
      	... 14 more
      Caused by: org.jboss.weld.exceptions.WeldException
      	at org.jboss.weld.bean.proxy.InterceptedSubclassFactory.addMethodsFromClass(InterceptedSubclassFactory.java:236)
      	at org.jboss.weld.bean.proxy.InterceptedSubclassFactory.addMethods(InterceptedSubclassFactory.java:119)
      	at org.jboss.weld.bean.proxy.ProxyFactory.createProxyClass(ProxyFactory.java:477)
      	at org.jboss.weld.bean.proxy.ProxyFactory.getProxyClass(ProxyFactory.java:390)
      	... 27 more
      Caused by: java.lang.NullPointerException
      	at org.jboss.weld.bean.proxy.InterceptedSubclassFactory.createDelegateToSuper(InterceptedSubclassFactory.java:281)
      	at org.jboss.weld.bean.proxy.InterceptedSubclassFactory.createDelegateToSuper(InterceptedSubclassFactory.java:275)
      	at org.jboss.weld.bean.proxy.InterceptedSubclassFactory.createDelegateMethod(InterceptedSubclassFactory.java:459)
      	at org.jboss.weld.bean.proxy.InterceptedSubclassFactory.addMethodsFromClass(InterceptedSubclassFactory.java:148)
      	... 30 more
      
      

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  manovotn Matej Novotny
                  Reporter:
                  andreas.r. Andreas R.
                • Votes:
                  1 Vote for this issue
                  Watchers:
                  5 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: