Hi,
please clear situation for me:

I have two version of com.bar module
one com.baz that depends on com.bar
one com.foo that depends on both com.bar and com.baz

Two layer:
layer 1: com.baz and com.bar@1
---------------------------

module com.bar {//version1
    exports com.bar;
}

------------------

//Bar.java

package com.bar;
public class Bar {
    public String bar(){ return "bar1";}
}

module com.baz {
        requires com.bar;
        exports com.baz;
}

-----------------

//Baz.java

package com.baz;

import com.bar.Bar;
public class Baz {
    public String baz(){ return new Bar().bar();}
    public Bar bar(){
        return new Bar();
    }
}

layer 2: com.foo and com.bar@2
--------------------
 module com.bar {//version2

    exports com.bar;
}

-------------

//Bar.java

package com.bar;

public class Bar {
    public String bar(){ return "bar2";}
}

-------------

module com.foo {
        requires com.bar;
        requires com.baz;
}

-------------

Foo.java

package com.foo;

import com.bar.Bar;
import com.baz.Baz;

public class Main {
    public static void main(String[] args) {
        System.out.println(new Baz().baz());
        System.out.println(new Bar().bar());
    }
}

Result:

bar1
bar2

Good. So we can have different versions of same module.

But, my question arise from section "Implied readability" of

"The State of the Module System" document:
"The public modifiers mean that any module that depends upon the
java.sql module
will read not only the java.sql module but also the java.logging and
java.xml modules. "

Based on this paragraph we can edit module descriptors for modules com.foo
and com.baz as:
--------------------

module com.baz {
        requires public com.bar;
        exports com.baz;
}

--------------

module com.foo {
        requires com.baz;
}

But result is:

bar1
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(java.base@9.0/Native
Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(java.base@9.0
/NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(java.base@9.0
/DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(java.base@9.0/Method.java:531)
        at jakeplus.minicontainer.Bootstrapper.main(java.base@9.0
/Bootstrapper.java:67)
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

The exception message says: com.foo cannot read com.bar. Why?
Is not two situation equivalent? (before Implied readability and after)
This is bug?

Best Regards,
Ali Ebrahimi

Reply via email to