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

Weld SE, Instance<> and @New - NPE

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Minor
    • 1.1.0.Beta1
    • 1.0.1.Final
    • Built-in beans
    • None
    • Workaround Exists
    • Hide

      Specifically declare the @New.value, like:
      @Inject
      @New(SomeBean.class)
      private Instance<SomeBean> i;

      Show
      Specifically declare the @New.value, like: @Inject @New(SomeBean.class) private Instance<SomeBean> i;

    Description

      For 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. Not sure about this.

      Anyways, NPE should be changed to some more descriptive and friendly exception, describing what is wrong.

      Please see the forum topic: http://seamframework.org/Community/WeldSEInstanceAndNewNPE

      Attachments

        Activity

          People

            nickarls Nicklas Karlsson (Inactive)
            wujek_jira Wujek Srujek (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: