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

NullPointerException thrown when using beanManager.getReference(...) or getInstance(...) where the Producer method for the bean is expecting an InjectionPoint.

XMLWordPrintable

      I have a problem with the current Weld 2 code, seems to be throwing an NPE instead of using the InjectionPoint that I am providing the BeanManager with.

      This can be reproduced right now by checking out the forge core repository branch 2.0. Just run, mvn clean install.

      https://github.com/forge/core/tree/2.0

      The crux of the matter, we have a producer method in a CDI instance A:

      @Produces
      public static Coverter<?,?> produceRemoteConverter(AddonRegistry registry, InjectionPoint ip)

      There are, however, no injection points actually consuming this type/producer method from within CDI instance A. (And adding one would not really help.)

      In CDI instance, B, however, we are using the following code, with a reference to the BeanManager from CDI instance A, to get an instance of a Converter:

      Bean<R> bean = (Bean<R>) manager.resolve(manager.getBeans(type));
      context = manager.createCreationalContext(bean);
      Object delegate = manager.getInjectableReference(injectionPoint, context);

      We have an InjectionPoint for the Converter type in CDI instance B, and are delegating to container A to get the instance (using an extension.)

      However, even though we are passing in our own InjectionPoint(B) into CDI instance A, CDI instance A still tries to look up the InjectionPoint on its internal stack, and throws a NullpointerException.

      I think this is a bug, since InjectionPoint is an interface, (but obviously very edge case if so.)

      Any help would be appreciated. Otherwise, we have no way to support looking up beans for types which are produced with Producer Methods requiring an injection point (those without work fine, and normal type lookups obviously work fine.)

      Caused by: java.lang.NullPointerException
          at org.jboss.weld.serialization.InjectionPointHolder.<init>(InjectionPointHolder.java:48)
          at org.jboss.weld.util.bean.SerializableForwardingInjectionPoint.<init>(SerializableForwardingInjectionPoint.java:33)
          at org.jboss.weld.bean.builtin.InjectionPointBean.newInstance(InjectionPointBean.java:51)
          at org.jboss.weld.bean.builtin.InjectionPointBean.newInstance(InjectionPointBean.java:31)
          at org.jboss.weld.bean.builtin.AbstractDecorableBuiltInBean.create(AbstractDecorableBuiltInBean.java:62)
          at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:69)
          at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:701)
          at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:768)
          at org.jboss.weld.manager.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:786)
          at org.jboss.weld.injection.ParameterInjectionPointImpl.getValueToInject(ParameterInjectionPointImpl.java:71)
          at org.jboss.weld.injection.MethodInjectionPoint.getParameterValues(MethodInjectionPoint.java:140)
          at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstance(MethodInjectionPoint.java:79)
          at org.jboss.weld.injection.producer.ProducerMethodProducer.produce(ProducerMethodProducer.java:92)
          at org.jboss.weld.injection.producer.AbstractMemberProducer.produce(AbstractMemberProducer.java:188)
          at org.jboss.weld.bean.AbstractProducerBean.create(AbstractProducerBean.java:190)
          at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:69)
          at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:701)
          at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:729)
          at org.jboss.weld.util.ForwardingBeanManager.getReference(ForwardingBeanManager.java:60)
          at org.jboss.weld.bean.builtin.BeanManagerProxy.getReference(BeanManagerProxy.java:67)
          at org.jboss.forge.container.impl.RemoteInstanceImpl$1.call(RemoteInstanceImpl.java:47)
          at org.jboss.forge.container.util.ClassLoaders.executeIn(ClassLoaders.java:34)
          ... 93 more

            rhn-engineering-jharting Jozef Hartinger
            lincolnthree Lincoln Baxter III (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: