RFR: JDK-8220702: compiling in the context of an automatic module disallows --add-modules ALL-MODULE-PATH

Alex Buckley alex.buckley at oracle.com
Wed Apr 10 18:51:40 UTC 2019

// Adding jigsaw-dev -- this topic is slightly deeper than it appears.

On 4/9/2019 4:43 AM, Jan Lahoda wrote:
> Currently, when compiling an unnamed module, --add-modules
> ALL-MODULE-PATH adds all modules from the module path to the module
> graph, so that the unnamed module can refer to them.

(See also http://openjdk.java.net/jeps/261#Root-modules plus the section 
"Root modules" in the java.lang.module package spec.)

> When compiling a named module, this option is not allowed, as it would
> be confusing, as it cannot modify the dependencies of the named module.
> But, when compiling a code in the context of an automatic module using
> --patch-module, e.g.:
> javac --module-path <automatic-module> --patch-modules
> <automatic-module-name>=<dir> ...
> The --add-modules ALL-MODULE-PATH is still disallowed, but it may make
> sense to use it, as it may affect the set of classes available for the
> sources that are being compiled. Compiling in the context of an
> automatic module may be useful esp. in when patching multiple modules at
> once (which is supported by --patch-module), e.g. to build tests. (Seems
> that also at least the use of javadoc in Maven may lead to a similar
> setting as well, see the JBS bug.)

JEP 261 doesn't discuss compiling code "in the context of an automatic 
module", and javac's reference guide doesn't imply that `--patch-module` 
supports it, but it is clearly a plausible and useful thing to do, so 
thanks for calling it out.

There is a question to be answered: When the compiler compiles code in 
an automatic module (due to the code being observed in a directory that 
is specified to --patch-module), then what is the _default set of root 
modules_ for the automatic module?

I expect the answer is: the same as the default set of root modules for 
the unnamed module. And actually, for the `javac` invocation shown 
above, which is single-module mode, this answer is given in the "Compile 
time" section of JEP 261 
(http://openjdk.java.net/jeps/261#Compile-time). Unfortunately, the 
answer is only accidentally right, because the section did not envisage 
compiling code in an automatic module; for the `javac` invocation above, 
the section says "source files will be compiled as members of the 
unnamed module".

So, there's another question to be answered: Does `javac` support 
compiling code in an automatic module in single-module mode, or 
multi-module both, or either? Once we know this, we can update the 
"Compile time" section and answer the set-of-root-modules question.

> The proposal is to allow the --add-modules ALL-MODULE-PATH option when
> compiling code in the context of an automatic module.

I support this proposal, subject to the questions raised above.

A CSR will be needed; in addition to specifying the things mentioned 
above, it can clarify the description of ALL-MODULE-PATH w.r.t. when it 
can be used at compile time. Currently, the description seems unsure 
about when it can be used.

(For reference, the text: "As a final special case, at both run time and 
link time, if <module> is ALL-MODULE-PATH then all observable modules 
found on the relevant module paths are added to the root set. 
ALL-MODULE-PATH is valid at both compile time and run time. This is 
provided for use by build tools such as Maven, which already ensure that 
all modules on the module path are needed. It is also a convenient means 
to add automatic modules to the root set.")


> Proposed patch: http://cr.openjdk.java.net/~jlahoda/8220702/webrev.01/
> JBS: https://bugs.openjdk.java.net/browse/JDK-8220702
> What do you think?
> Thanks,
>      Jan

More information about the compiler-dev mailing list