question on exports to

Jochen Theodorou blackdrag at gmx.org
Tue May 31 20:40:14 UTC 2016


Hi all,

Let me outline an example:

named module GeneralInvoker, exports com.foo.gi.

package com.foo.gi;
public class TheInvoker{
   public static Object invoke(Object receiver, String name, Object.. 
args) {
     Method m = receiver.getClass().getDeclaredMethod(name, toClass(args));
    return m.invoke(args);
   }
    .....
}

named module MyOtherLib, requires GeneralInvoker, no exports

package my.lib;
public class SomeClassOfTheLibrary {
   public void invokeBarOnArgument(Object x) {
     TheInvoker.invoke(x, "bar");
   }
   ....
}

(obviously this is just an outline, not real classes)

So if I see this right, then calling TheInvoker.invoke will fail, 
because my.lib.SomeClassOfTheLibrary is not accessible by 
com.foo.gi.TheInvoker. And am I right in that if MyOtherLib adds a 
"export my.lib to GeneralInvoker", this will then work?

Now some advanced questions ;)

assuming MyOtherLib also requires YetAnotherLib and has the exports-to 
in the module descriptor... does it automatically imply readability For 
GeneralInvoker on YetAnotherLib (only exported parts of course)?

Assuming this is not the case... can I use Module#addReads, with the 
caller being from GeneralInvoker and the other Module being 
YetAnotherLib, to create that readability?

And even more difficult:

Assuming TheInvoker spawns a new class loader and a class within that to 
do the actual method invocation. So far I assume the module of that 
class would the unnamed module. As such I have access to the exports of 
MyOtherLib and YetAnotherLib.

But how do I establish that class to be able to access 
my.lib.SomeClassOfTheLibrary?

I would have assumed Layers can do it, but I don't see how the API gives 
me that. Having another exports-to in the module descriptor of 
MyOtherLib will I think not work, since even if I define a naming 
convention, this module does not exist at compile time.

Or should I trick Java by creating a dummy module with a certain name, 
that MyOtherLib can export-to, but is used at compile time only?

Here I might be able to use Layer to define my module... unless the JVM 
expects that module to exists7find when it loads MyOtherLib, in which 
case I am stuck again.

So what am I missing or is this final part really not possible?


bye Jochen


More information about the jigsaw-dev mailing list