[Question] Accessibility of each modules
Alan Bateman
Alan.Bateman at oracle.com
Tue Sep 5 11:31:30 UTC 2017
On 05/09/2017 12:01, KUBOTA Yuji wrote:
> Hi all,
>
> I have a question about accessibility of each modules: unnamed,
> automatic and named modules.
> * unnamed: the JAR compiled by java 8 and speficied by --class-path.
> * automatic: the JAR compiled by Java 8 and specified by --module-path.
> * named: the modular JAR.
For the modular JAR case then the term to use is "explicit module".
>
> I ran quick-start's example program on java 9+181 and 8u141, and
> confirmed the following results.
> * Named modules can call autonamed modules.
Yes, assuming the explicit module reads the automatic module. As an
automatic module exports all packages then it means code in the explicit
module can access all public members of public classes in the automatic
module.
> * Automatic modules can *NOT* call named modules.
Automatic modules read all named modules (in the module graph), they
also read all unnamed modules. I have not studied your github project
but you should see that code in the automatic module can access all
public members of public classes in packages exported by the explicit
module (because it reads the explicit module).
> * We can run unnamed modules with only unnamed modules.
I'm not what you mean by this because you can mix the class path with
named modules. When you run HelloWorld on the class path then you are
doing this, although it might not be obvious.
If it helps then the code in an unnamed module an access all public
members of public classes in all unnamed modules. It can also access all
public members of public classes in the packages exported by named
modules (automatic modules are named modules, they export all packages).
>
> I guessed that every modules can be accessed each other if
> `--illegal-access=permit` or/and `--add-exports` is given, but it does
> not seems to be fine.
The `--add-exports` option is for breaking encapsulation, it can be used
to change a module so that it exports an otherwise concealed package to
another named module or to all unnamed modules.
The `--illegal-access=<value>` option is specific to the standard and
JDK modules.
> I guess that modules and classes (unnamed module) cannot be existed at
> the same time because `BuiltinClassLoader` seems to branch by
> `packageToModule` field in it.
No, that is just an implementation detail. The issue that was chosen not
to tackle in JDK 9 is the issue of multiple modules in the boot layer
with the same non-exported package. This topic has a lot of complexity
and compatibility issues for (non-JDK) code. It will be looked in the
future.
-Alan
More information about the jigsaw-dev
mailing list