Doubts on automatic modules and what is exported at runtime

Thomas Watson tjwats at gmail.com
Fri Oct 5 21:23:59 UTC 2018


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


More information about the jigsaw-dev mailing list