Does --add-exports imply --add-reads??

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Does --add-exports imply --add-reads??

Stephan Herrmann
Hi,

Given these sources:

src/mod.one/module-info.java
//---
module mod.one {
         requires transitive java.sql;
}
//---

src/mod.one/p/X.java
//---
package p;
public class X {
         public static java.sql.Connection getConnection() {
                 return null;
         }
}
//---

src/mod.two/module-info.java
//---
module mod.two {
         requires java.sql;
}
//---

src/mod.two/q/Y.java
//---
package q;
public class Y {
    java.sql.Connection con = p.X.getConnection();
}
//---

Javac accepts the program when invoked like this:

$ javac -d bin -source 9 --module-source-path src --add-exports mod.one/p=mod.two \
    src/mod.one/module-info.java src/mod.one/p/X.java \
    src/mod.two/module-info.java src/mod.two/q/Y.java

How come javac allows Y.java to access p.X, although mod.two does not read mod.one?

Is javac interpreting --add-exports to imply an additional --add-reads?

best,
Stephan
Reply | Threaded
Open this post in threaded view
|

Re: Does --add-exports imply --add-reads??

Naman Nigam
Well, this looks similar to what the increasing readability
<http://openjdk.java.net/jeps/261#Increasing-readability%E2%80%8B> section
in JEP-261 reads.

As a consequence, code in the source module will be able to access types in
> a package of the target module at both compile time and run time if that
> package is exported via an exports clause in the source module's
> declaration, an invocation of the Module::addExports method
> <http://download.java.net/java/jdk9/docs/api/java/lang/reflect/Module.html#addExports-java.lang.String-java.lang.reflect.Module->,
> or an instance of the --add-exports option


Another doubt, if it could add to the current context, would be, what does
the term "invocation of an unrestricted form" precisely mean in the
document?

        Regards
    Naman Nigam


On Tue, Jul 10, 2018 at 9:26 PM Stephan Herrmann <[hidden email]>
wrote:

> Hi,
>
> Given these sources:
>
> src/mod.one/module-info.java
> //---
> module mod.one {
>          requires transitive java.sql;
> }
> //---
>
> src/mod.one/p/X.java
> //---
> package p;
> public class X {
>          public static java.sql.Connection getConnection() {
>                  return null;
>          }
> }
> //---
>
> src/mod.two/module-info.java
> //---
> module mod.two {
>          requires java.sql;
> }
> //---
>
> src/mod.two/q/Y.java
> //---
> package q;
> public class Y {
>     java.sql.Connection con = p.X.getConnection();
> }
> //---
>
> Javac accepts the program when invoked like this:
>
> $ javac -d bin -source 9 --module-source-path src --add-exports
> mod.one/p=mod.two \
>     src/mod.one/module-info.java src/mod.one/p/X.java \
>     src/mod.two/module-info.java src/mod.two/q/Y.java
>
> How come javac allows Y.java to access p.X, although mod.two does not read
> mod.one?
>
> Is javac interpreting --add-exports to imply an additional --add-reads?
>
> best,
> Stephan
>
Reply | Threaded
Open this post in threaded view
|

Re: Does --add-exports imply --add-reads??

Alan Bateman
In reply to this post by Stephan Herrmann
There seems to be a javac bug here, I've created the following to track it:
     https://bugs.openjdk.java.net/browse/JDK-8207032

-Alan

On 10/07/2018 16:56, Stephan Herrmann wrote:

> Hi,
>
> Given these sources:
>
> src/mod.one/module-info.java
> //---
> module mod.one {
>         requires transitive java.sql;
> }
> //---
>
> src/mod.one/p/X.java
> //---
> package p;
> public class X {
>         public static java.sql.Connection getConnection() {
>                 return null;
>         }
> }
> //---
>
> src/mod.two/module-info.java
> //---
> module mod.two {
>         requires java.sql;
> }
> //---
>
> src/mod.two/q/Y.java
> //---
> package q;
> public class Y {
>    java.sql.Connection con = p.X.getConnection();
> }
> //---
>
> Javac accepts the program when invoked like this:
>
> $ javac -d bin -source 9 --module-source-path src --add-exports
> mod.one/p=mod.two \
>    src/mod.one/module-info.java src/mod.one/p/X.java \
>    src/mod.two/module-info.java src/mod.two/q/Y.java
>
> How come javac allows Y.java to access p.X, although mod.two does not
> read mod.one?
>
> Is javac interpreting --add-exports to imply an additional --add-reads?
>
> best,
> Stephan