[weld-issues] [JBoss JIRA] Commented: (WELD-471) Weld SE, Instance<> and @New - NPE

Nicklas Karlsson (JIRA) jira-events at lists.jboss.org
Mon Mar 22 09:18:45 EDT 2010


    [ https://jira.jboss.org/jira/browse/WELD-471?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12521140#action_12521140 ] 

Nicklas Karlsson commented on WELD-471:
---------------------------------------

I think the injection system misinterprets the @New as belonging to the @Inject Instance and not to what the Instance is injecting. If I guard myself against the NPE:s I end up with a 

org.jboss.weld.exceptions.DefinitionException: WELD-000816 Cannot determine constructor to use for  javax.enterprise.inject.Instance<[class org.jboss.weld.tests.scope.up2.Foo]>

for a 

org.jboss.weld.bean-test-NewManagedBean-javax.enterprise.inject.Instance<org.jboss.weld.tests.scope.up2.Foo>

which is a @New @Instance implementation

Have to check with Pete how to handle it or what is the correct behaviour

> Weld SE, Instance<> and @New - NPE
> ----------------------------------
>
>                 Key: WELD-471
>                 URL: https://jira.jboss.org/jira/browse/WELD-471
>             Project: Weld
>          Issue Type: Bug
>          Components: Built-in beans
>    Affects Versions: 1.0.1.Final
>            Reporter: Wujek Srujek
>            Priority: Minor
>
> 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

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the weld-issues mailing list