Doubts on automatic modules and what is exported at runtime

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

Doubts on automatic modules and what is exported at runtime

Thomas Watson-2
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
Reply | Threaded
Open this post in threaded view
|

Re: Doubts on automatic modules and what is exported at runtime

Alan Bateman
On 05/10/2018 22:23, Thomas Watson wrote:

> :
>
> 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
Reply | Threaded
Open this post in threaded view
|

Re: Doubts on automatic modules and what is exported at runtime

Thomas Watson-2
Sorry to revisit this old topic.  I was testing this again with the latest
Java 11 on adopt open jdk and it still appears to be an issue. Did this bug
ever get opened and addressed?

Thanks
Tom

On Fri, Oct 5, 2018 at 5:04 PM Alan Bateman <[hidden email]> wrote:

> On 05/10/2018 22:23, Thomas Watson wrote:
> > :
> >
> > 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
>
Reply | Threaded
Open this post in threaded view
|

Re: Doubts on automatic modules and what is exported at runtime

Alan Bateman
On 12/11/2019 16:48, Thomas Watson wrote:
> Sorry to revisit this old topic.  I was testing this again with the
> latest Java 11 on adopt open jdk and it still appears to be an issue.
> Did this bug ever get opened and addressed?
Yes, it was fixed in JDK 12 via JDK-8211825 [1][2].

-Alan

[1] https://bugs.openjdk.java.net/browse/JDK-8211825
[2]
https://mail.openjdk.java.net/pipermail/jigsaw-dev/2018-October/013977.html