Discussion:
Does --add-exports imply --add-reads??
Stephan Herrmann
2018-07-10 15:56:02 UTC
Permalink
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
Naman Nigam
2018-07-10 18:06:49 UTC
Permalink
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
Hi,
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 -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
Alan Bateman
2018-07-11 08:18:17 UTC
Permalink
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
Post by Stephan Herrmann
Hi,
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 -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
Continue reading on narkive:
Loading...