Alternatives to automatic modules as a concept

Gunnar Morling gunnar at
Sun Mar 19 21:48:39 UTC 2017

Is there a way to execute some code when a module is "activated" or
resolved? I'm not sure what the current word is in Jigsaw terms, but I
hope it becomes clearer in the following.

To overcome the issue of dependency cycles between slf4j API and
implementations (when treating them as named modules by adding module
descriptors, as required for using slf4j in a modular runtime image),
I've been experimenting with injecting a class into the slf4j.api
module which establishes the read from API to impl dynamically:

    public void addImplReads() {
        Module apiModule = org.slf4j.Logger.getClass().getModule();
        apiModule.addReads( apiModule.getLayer().findModule(
"slf4j.simple").get() );

This technique requires "someone" to call this method, before invoking
any method on the slf4j API. That could be done by the user's
application, but it'd be much more user-friendly if this could happen
automatically if the slf4j API module is resolved. Hence I'm trying to
figure whether one can register a callback or similar and be notified
in that case.



2017-03-17 15:20 GMT+01:00 Alan Bateman <Alan.Bateman at>:
> On 17/03/2017 14:16, David M. Lloyd wrote:
>> Hmm, so automatic modules explicitly are going to allow cycles then? How
>> is that going to not hinder migration, if cycles are disallowed once the
>> thing is properly modularized?
> Automatic modules are for libraries that have not been migrated. The
> maintainers have to fix their issues as part of migration. When a module
> declaration is synthesized for an automatic module then it only requires
> java.base so it can't be involved in a cycle in the dependency graph.
> -Alan

More information about the jigsaw-dev mailing list