Question on Implied readability
Ali Ebrahimi
ali.ebrahimi1781 at gmail.com
Mon Nov 2 20:02:20 UTC 2015
Hi Alan,
I don't khow how you testing this.
But this is simple possible test case:
public class Test {
public static void main(String[] args) throws Exception {
ModuleFinder finder1 = ModuleFinder.of(Paths.get("mods1"));
Configuration cfg1 = Configuration.resolve(finder1,
Layer.boot(),ModuleFinder.empty(),"com.bar","com.baz");
ModuleClassLoader cl1 = new ModuleClassLoader(cfg1);
Layer layer1 = Layer.create(cfg1, m -> cl1);
ModuleFinder finder2 = ModuleFinder.of(Paths.get("mods2"));
Configuration cfg2 = Configuration.resolve(finder2,
layer1,ModuleFinder.empty(),"com.bar","com.foo");
ModuleClassLoader cl2 = new ModuleClassLoader(cl1,cfg2);
Layer layer2 = Layer.create(cfg2, m -> cl2);
System.out.println("layer2.modules()\n"+layer2.modules());
System.out.println("layer1.modules()\n"+layer1.modules());
Module foo = layer2.findModule("com.foo").get();
Module bar2 = layer2.findModule("com.bar").get();
System.out.println("foo.canRead(bar2) -> "+foo.canRead(bar2));
Module bar1 = layer1.findModule("com.bar").get();
System.out.println("foo.canRead(bar1) -> "+foo.canRead(bar1));
ClassLoader fooModuleLoader = layer2.findLoader("com.foo");
Class<?> mainClass = fooModuleLoader.loadClass("com.foo.Main");
Test.class.getModule().addReads(mainClass.getModule());
Method mainMethod = mainClass.getMethod("main", String[].class);
mainMethod.invoke(null, (Object)new String[0]);
}
And Result:
layer2.modules()
[module com.foo, module com.bar]
layer1.modules()
[module com.baz, module com.bar]
foo.canRead(bar2) -> false
foo.canRead(bar1) -> false
bar1
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(java.base at 9.0/Native
Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(java.base at 9.0/NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(java.base at 9.0/DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(java.base at 9.0/Method.java:531)
at com.test.Test.main(com.test/Test.java:48)
Caused by: java.lang.IllegalAccessError: class com.foo.Main (in module: com.foo)
cannot access class com.bar.Bar (in module: com.bar), com.foo cannot
read com.bar
at com.foo.Main.main(com.foo/Main.java:12)
... 5 more
Note that I get above result if Implied readability used.
On Mon, Nov 2, 2015 at 10:18 PM, Alan Bateman <Alan.Bateman at oracle.com>
wrote:
> On 02/11/2015 13:20, Ali Ebrahimi wrote:
>
>> :
>>
>>
> I can't rule out a bug of course but I would need to see an outline of
> what jakeplus.minicontainer.Bootstrapper is doing so that I can see how the
> layers and class loaders are arranged.
This is simple extension to jake that build layers based on config from
command line.
Sample Input:
<layer mp="mods1">
<module name="com.bar" standalone="true" root-module="false"/>
<module name="com.baz" standalone="true" root-module="true"/>
<layer mp="mods2">
<module name="com.bar" standalone="true" root-module="true"/>
<module name="com.foo" standalone="true" root-module="true"
main-class="com.foo.Main"/>
</layer>
</layer>
>
> -Alan.
>
--
Best Regards,
Ali Ebrahimi
More information about the jigsaw-dev
mailing list