You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openwebbeans.apache.org by "Mark Struberg (JIRA)" <ji...@apache.org> on 2011/07/23 14:29:09 UTC

[jira] [Commented] (OWB-597) StackOverFlow when injecting product in same bean where @Produces is placed

    [ https://issues.apache.org/jira/browse/OWB-597?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13069947#comment-13069947 ] 

Mark Struberg commented on OWB-597:
-----------------------------------

Hi!

I think this sample might be not valid because you inject the bean you produce into the producer itself which is not allowed by the spec.
I'd need to get a bit more information: is the Alternative activated or not?

The reason for the question is that @Named is treated very special. See 
> 2.3.1. Built-in qualifier types
> If a bean does not explicitly declare a qualifier other than @Named, the bean has exactly one 
> additional qualifier, of type @Default. This is called the default qualifier.

So if the Alternative is activated, then Weld (and OWB probably too) must abort the creation at least with an AmbiguousResolutionException because there are 2 beans which satisfy the   
@Inject private Product product; 
InjectionPoint:
1.) the Product class itself having Qualifiers @Any and @Default
2.) the producer method having Qualifiers @Any, @Default and @Named

If the Alternative didn't get activated then we have a cyclic injection of @Dependent beans which is _not_ allowed by the CDI spec imo. See 
> Chapter 5. Dependency injection, lookup and EL
> The container is not required to support circular chains of dependencies where every bean participating in the chain has a pseudo-scope. 

which is exactly the case in your example. I'm really curious how Weld does handle this!

> StackOverFlow when injecting product in same bean where @Produces is placed
> ---------------------------------------------------------------------------
>
>                 Key: OWB-597
>                 URL: https://issues.apache.org/jira/browse/OWB-597
>             Project: OpenWebBeans
>          Issue Type: Bug
>    Affects Versions: 1.1.1
>         Environment: OWB 1.1.1-SNAPSHOT trunk
>            Reporter: Martin Kočí
>            Assignee: Gurkan Erdogdu
>            Priority: Critical
>
> public class SomeBean {
> 	@Inject private Product product;
> 	
> 	@Produces @Named public Product getProduct() {return new Product();}
> 	
> 	@Alternative
> 	public static class Product {}
> }
> + use @Inject in client:
> @Inject  Product product;
> leads to:
> Exception in thread "main" java.lang.StackOverflowError
> 	at org.apache.webbeans.component.AbstractOwbBean.create(AbstractOwbBean.java:182)
> 	at org.apache.webbeans.context.DependentContext.getInstance(DependentContext.java:69)
> 	at org.apache.webbeans.context.AbstractContext.get(AbstractContext.java:190)
> 	at org.apache.webbeans.container.BeanManagerImpl.getReference(BeanManagerImpl.java:963)
> 	at org.apache.webbeans.component.AbstractProducerBean.getParentInstance(AbstractProducerBean.java:114)
> 	at org.apache.webbeans.component.ProducerMethodBean.createDefaultInstance(ProducerMethodBean.java:188)
> 	at org.apache.webbeans.component.ProducerMethodBean.createInstance(ProducerMethodBean.java:155)
> 	at org.apache.webbeans.component.AbstractOwbBean.createNewInstance(AbstractOwbBean.java:235)
> 	at org.apache.webbeans.portable.creation.AbstractProducer.produce(AbstractProducer.java:81)
> 	at org.apache.webbeans.component.InjectionTargetWrapper.produce(InjectionTargetWrapper.java:142)
> 	at org.apache.webbeans.component.AbstractOwbBean.create(AbstractOwbBean.java:181)
> 	at org.apache.webbeans.context.DependentContext.getInstance(DependentContext.java:69)
> 	at org.apache.webbeans.context.AbstractContext.get(AbstractContext.java:190)
> 	at org.apache.webbeans.container.BeanManagerImpl.getReference(BeanManagerImpl.java:963)
> 	at org.apache.webbeans.container.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:841)
> 	at org.apache.webbeans.inject.AbstractInjectable.inject(AbstractInjectable.java:133)
> 	at org.apache.webbeans.inject.InjectableField.doInjection(InjectableField.java:59)
> 	at org.apache.webbeans.component.AbstractInjectionTargetBean.injectField(AbstractInjectionTargetBean.java:384)
> 	at org.apache.webbeans.component.AbstractInjectionTargetBean.injectFields(AbstractInjectionTargetBean.java:321)
> 	at org.apache.webbeans.portable.creation.InjectionTargetProducer.inject(InjectionTargetProducer.java:95)
> 	at org.apache.webbeans.component.InjectionTargetWrapper.inject(InjectionTargetWrapper.java:80)
> 	at org.apache.webbeans.component.AbstractOwbBean.create(AbstractOwbBean.java:182)
> 	at org.apache.webbeans.context.DependentContext.getInstance(DependentContext.java:69)
> 	at org.apache.webbeans.context.AbstractContext.get(AbstractContext.java:190)
> 	at org.apache.webbeans.container.BeanManagerImpl.getReference(BeanManagerImpl.java:963)
> 	at org.apache.webbeans.component.AbstractProducerBean.getParentInstance(AbstractProducerBean.java:114)
> 	at org.apache.webbeans.component.ProducerMethodBean.createDefaultInstance(ProducerMethodBean.java:188)
> 	at org.apache.webbeans.component.ProducerMethodBean.createInstance(ProducerMethodBean.java:155)
> 	at org.apache.webbeans.component.AbstractOwbBean.createNewInstance(AbstractOwbBean.java:235)
> 	at org.apache.webbeans.portable.creation.AbstractProducer.produce(AbstractProducer.java:81)
> 	at org.apache.webbeans.component.InjectionTargetWrapper.produce(InjectionTargetWrapper.java:142)
> 	at org.apache.webbeans.component.AbstractOwbBean.create(AbstractOwbBean.java:181)
> 	at org.apache.webbeans.context.DependentContext.getInstance(DependentContext.java:69)
> 	at org.apache.webbeans.context.AbstractContext.get(AbstractContext.java:190)
> Weld handles this situation. 

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira