Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8222396

Allow "--add-modules ALL-MODULE-PATH" when compiling in the context of an automatic module

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P2 P2
    • 13
    • tools
    • None
    • behavioral
    • minimal
    • add/remove/modify command line option
    • JDK

      Summary

      Permit the use of --add-modules ALL-MODULE-PATH when compiling in the context of an automatic module.

      Problem

      The option --patch-module can be used to compile source code "as if" it is part of an explicit named module. For example, a test can be "injected" into an explicit named module by compiling in single-module mode: (assume the path directory contains explicit.jar, which has a module-info.class)

      $ javac -d out
        --module-path path
        --patch-module explicit=test/explicit/src
        test/explicit/src/explicit/ExplicitTest.java

      Interestingly, --patch-module can also be used to compile source code "as if" it is part of an implicit named module, i.e., in the context of an automatic module. Tests can be "injected" into multiple modules at once -- both explicit and implicit -- by compiling in multi-module mode: (assume the path directory contains both explicit.jar, which has a module-info.class, and automatic.jar, which has no module-info.class)

      $ javac -d out
        --module-source-path dummy
        --module-path path
        --patch-module explicit=test/explicit/src
        --patch-module automatic=test/automatic/src
        test/explicit/src/explicit/ExplicitTest.java
        test/automatic/src/automatic/AutomaticTest.java

      Unfortunately, in this invocation of javac, the automatic module automatic does not read any other modules. This means that the test code "injected" into the module automatic cannot access the same APIs as the test code "injected" into the module explicit. The module explicit has requires directives that set up what explicit can read, but the module automatic has no requires directives.

      Solution

      When compiling source code in the unnamed module, it is legal to say --add-modules ALL-MODULE-PATH to add all the modules on the module path to the module graph. This lets the unnamed module (which has no requires directives of its own) read a set of modules without adding them one by one, e.g., --add-modules java.sql,java.desktop,java.xml. In contrast, when compiling source code in an explicit named module, the module has requires directives that specify precisely which modules to read, so it is not useful (and indeed not legal) to say --add-modules ALL-MODULE-PATH.

      Compiling source code in the context of an automatic module is closer to the former scenario (unnamed module) than the latter (explicit named module). An automatic module has no requires directives of its own, so it would be useful to say --add-modules ALL-MODULE-PATH to let it read all the modules on the module path without adding them one by one.

      More by accident than intent, it has not been legal to say --add-modules ALL-MODULE-PATH when compiling code in the context of an automatic module using --patch-module. This restriction should be removed.

      Specification

      Permit --add-modules ALL-MODULE-PATH when compiling source code that is associated with either an unnamed module or an automatic module (i.e., code being compiled in the context of an automatic module).

            jlahoda Jan Lahoda
            webbuggrp Webbug Group
            Alex Buckley, Jonathan Gibbons
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: