3 Replies Latest reply on Mar 22, 2010 2:19 PM by Nicklas Karlsson

    Weld SE, Instance<> and @New - NPE

    Wujek Srujek Newbie
      Hi. I have a bean:

      @ApplicationScoped
      public class SomeBean {

          private double d = Math.random();

          public double getD() {
              return d;
          }
      }

      and an injection point:

      @Inject
      @New
      private Instance<SomeBean> i;

      and when I start Weld SE I get:

      Exception in thread "main" java.lang.NullPointerException
           at org.jboss.weld.util.Beans.getInitializerMethods(Beans.java:395)
           at org.jboss.weld.bean.AbstractClassBean.initInitializerMethods(AbstractClassBean.java:252)
           at org.jboss.weld.bean.AbstractClassBean.<init>(AbstractClassBean.java:164)
           at org.jboss.weld.bean.ManagedBean.<init>(ManagedBean.java:317)
           at org.jboss.weld.bean.NewManagedBean.<init>(NewManagedBean.java:66)
           at org.jboss.weld.bean.NewManagedBean.of(NewManagedBean.java:48)
           at org.jboss.weld.bootstrap.AbstractBeanDeployer.createNewManagedBean(AbstractBeanDeployer.java:244)
           at org.jboss.weld.bootstrap.BeanDeployer.createBeans(BeanDeployer.java:124)
           at org.jboss.weld.bootstrap.BeanDeployment.deployBeans(BeanDeployment.java:151)
           at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:377)
           at org.jboss.weld.environment.se.Weld.initialize(Weld.java:79)
           at org.jboss.weld.environment.se.StartMain.go(StartMain.java:45)
           at test.Test.main(Test.java:10)

      When I specify @New.value:

      @Inject
      @New(SomeBean.class)
      private Instance<SomeBean> i;

      it works. The exception is thrown from within Weld core somewhere. According to the API, @New.value is optional and "defaults the value to the declared type of the injection point", and for Instance, "the required type is the type parameter specified at the injection point". So I think it should be able to take the type parameter and not result in an error?

      Is what causes the exception an invalid injection point definition? If it is, NPE should not be thrown anyways, I think.

      Wujek