Fwd: Add reads to open module

Alan Bateman Alan.Bateman at oracle.com
Mon May 17 15:55:35 UTC 2021


On 17/05/2021 16:43, Christian Beikov wrote:
> Hi,
>
> I have a use case where I generate some code and that code refers to 
> classes of some module B.
>
> When the module A (an open module), into which I define that class, 
> has no read-edges to the module B, this fails saying that A does not 
> read B.
>
> That's fine and totally understandable, so I tried to add the 
> following code:
>
> moduleA.addReads("moduleB.pkg", moduleB)
>
> but this is not allowed as `addReads` only works if `this == 
> callerModule`.

Have you tried generating this in the <clinit> of the class that you 
inject? That should be a lot simpler than inject another class or 
complicating the existing API.

-Alan


>
> My workaround is to define a class into module A that can then call 
> this method.
>
> Is there a reason to this limitation? I mean the module is open 
> anyway, so anyone can just define a class into it, so why not also 
> allow calling addReads?




More information about the jigsaw-dev mailing list