[weld-dev] Circular dependencies between dependent bean constructors

Pete Muir pmuir at redhat.com
Mon Apr 12 07:57:20 EDT 2010


On 11 Apr 2010, at 06:49, Marius Bogoevici wrote:

> 
> On 2010-04-11, at 1:08 AM, Gavin King wrote:
> 
>> On Sat, Apr 10, 2010 at 11:18 PM, Marius Bogoevici
>> <marius.bogoevici at gmail.com> wrote:
>>> 
>>> On 2010-04-11, at 12:07 AM, Gavin King wrote:
>>> 
>>>> It's the nature of @Dependent scope that two injection points never
>>>> refer to the same instance, and that circularities are therefore an
>>>> impossibility.
>>> 
>>> Gavin, could you clarify that? From reading your comment, it seems like this use case
>>> implies unbound recursion: Foo injects Bar which in turns injects another instance of Foo
>>> (which is dependent on the first instance of Bar) which injects another instance of Bar etc.
>> 
>> Well, exactly. I mean, that's obvious from the definition of an
>> @Dependent object, right?
>> 
>> I mean, I don't quite follow what the source of doubt here is. Section
>> 6.4 is *very* explicit on this.
> 
> Yeah, it's not like the definition is ambiguous, but it's still good to have it summed up, I suppose -  especially since it's relatively easy to create such a use case (albeit inadvertently). 
> 
> Incidentally, in the preamble of chapter 5 is said that : "The container is not required to support circular chains of dependencies where every bean participating in the chain has a pseudo-scope."
> 
> So the question would be what happens in the case of @Dependent - it seems the spec should require a deployment error right away. Otherwise, implementors may choose to 'fix' this in a way that would violate the @Dependent definition. Also, it would be good to do the same if other pseudo-scopes are affected.

The source of doubt is as Marius says - this is quite an easy thing to code up in CDI, and the spec doesn't say that this a definition error (which it is normally clear about) and that if it's just allowed, the user can easily get a stack overflow.


More information about the weld-dev mailing list