#CyclicDependences with ServiceLoader

Jochen Theodorou blackdrag at gmx.org
Wed Nov 30 12:03:49 UTC 2016



On 30.11.2016 10:16, Alan Bateman wrote:
> On 30/11/2016 08:53, Jochen Theodorou wrote:
>
>> Hi,
>>
>> for my understanding I would like to ask the following:
>>
>> Given:
>> * Module A: uses service S1 and provides service S2
>> * Module B: uses service S2 and provides service S1
>>
>> In my understanding this forms a cyclic dependency, but since this is
>> not directly on the API level I am wondering if this is really one
>> "per definition as to be seen by jigsaw"?
> You need to expand the example a bit to say where S1 and S2 are, it's
> otherwise impossible to say if there is a cycle in the dependency graph.
>
> For example, there is no cycles here:
>
> module S {
>     exports p;
> }
>
> module A {
>     requires S;
>     uses p.S1;
>     provides p.S2 with ...
> }
>
> module B {
>     requires S;
>     uses p.S2;
>     provides p.S1 with ...
> }

if that is no cycle, then you answered my question already. There is no 
dependency between A and B in the sense that A uses a class from B and B 
uses a class from A - not directly at least. But there is one through 
the ServiceLoader, but it is still not cyclic for jigsaw, which looks 
for that only at the "direct" API usage

And it is easy to see that if we drop S and put the service interface 
for S1 in A and the one for S2 in B that we then get a cycle just 
because of "requires"

thanks,
Jochen


More information about the jigsaw-dev mailing list