Discussion:
Doubts on automatic modules and what is exported at runtime
Thomas Watson
2018-10-05 21:15:01 UTC
Permalink
Thomas Watson
2018-10-05 21:23:59 UTC
Permalink
Sorry for reposting the same topic, my other mail client produces emails
that the list doesn't like.

I have read several blogs and gone over the javadoc for Java 11 about
automatic modules but I running into an issue with the behavior of exports
from an automatic module. The ModuleDescriptor javadoc states the
following:

The module descriptor for an automatic module does not declare any
dependences (except for the mandatory dependency on java.base), and does
not declare any exported or open packages. Automatic module receive special
treatment during resolution so that they read all other modules in the
configuration. When an automatic module is instantiated in the Java virtual
machine then it reads every unnamed module and is treated as if all
packages are exported and open.

When launching Java I can use a module path that includes automatic modules
along with normal modules that require the automatic module names.
Everything works as expected, my normal modules are able to access the
packages included in the automatic module as if they are exported. Now I
try to use the ModuleLayer API to create a new layer which includes the
same set of automatic and normal modules. If I use one of
the defineModulesWithOneLoader method it all works just like it would when
loading them from the module path. But if I instead use one of
the defineModulesWithManyLoaders my normal modules that requires one of the
automatic modules can no longer load classes from the automatic module.

Looking at the method implementation
for jdk.internal.loader.Loader.initRemotePackageMap(Configuration,
List<ModuleLayer>) it seems that a loader will only delegate to other
loaders that contain module descriptors with real exports(). But the
automatic module reports an empty Set for exports. When determining what
loaders to delegate to should the code take into account that automatic
modules should be treated as if they export all packages they contain?
Thereby granting the normal module loader access to delegate to the loader
for the automatic module when trying to load packages contained in the
automatic loader?

Tom Watson
Alan Bateman
2018-10-05 22:04:31 UTC
Permalink
Post by Thomas Watson
When launching Java I can use a module path that includes automatic modules
along with normal modules that require the automatic module names.
Everything works as expected, my normal modules are able to access the
packages included in the automatic module as if they are exported. Now I
try to use the ModuleLayer API to create a new layer which includes the
same set of automatic and normal modules. If I use one of
the defineModulesWithOneLoader method it all works just like it would when
loading them from the module path. But if I instead use one of
the defineModulesWithManyLoaders my normal modules that requires one of the
automatic modules can no longer load classes from the automatic module.
You are correct. For module M1 and M2, mapped to class loaders L1 and
L2: if M1 reads M2 then L1 needs to delegate to L2 for each package that
M2 exports to M1. If M2 is an automatic module then it doesn't have any
exports to this is why the delegation isn't setup. I'll create a bug for
this.

-Alan

Loading...