Proposal: Allow illegal reflective access by default in JDK 9

Volker Simonis volker.simonis at
Fri May 19 09:48:23 UTC 2017

Hi Mark,

thanks for this proposal. I think it is pragmatic and well balanced.

While I personally agree with the advocates of a clean solution I also
understand the the needs of big (and slow) companies (including the
one I'm working for:) After all, the new default isn't that bad in my
opinion because it only affects applications/libraries on the class
path which is legacy anyway. If you convert your application/libraries
to modules it will still benefit from the full JPMS features and
restrictions. So altogether I think it is a good compromise.

I have some practical comments/suggestions though:

>From my understanding, at run-time, "open" implicates "exports" (i.e.
if a module M1 opens a package P for some other module M2 it also,
implicitly exports P to M2). The  "big kill switch" in both, its old
and in the newly proposed form, usually only refers to "enabling
reflective access" but doesn't explicitly mentions that it will also,
implicitly export the respective packages. Also, the usage of the
"kill switch" only produces warnings for reflective accesses which are
enabled by the option itself (and not at the same time, explicitly
allowed by --add-opens directives). But it doesn't warn about the
simple, non-reflective accesses to packages which are implicitly
exported by the kill switch as well.

I think that the "big kill switch" should also print warnings for
these simple, non-reflective accesses to packages which are implicitly
exported by the kill switch. Otherwise, this could lead to a situation
where users claim to be "JPMS-safe" because they did run with
"--illegal-access=warn" and didn't saw any warnings but then, after
the default will change to "--illegal-access=deny", their applications
will break because of simple accesses to non-exported packages.

I'm aware of the initial discussion about "--permit-illegal-access"
and that you decided not to issue warnings for the precise
`--add-opens` and `--add-exports` options [1]. But now, with the new
version of the "--illegal-access" option and the possibility to
enable/disable warnings, I think printing warnings for simple (i.e.
non-reflective) illegal accesses which are implicitly allowed
"--illegal-access" by would be useful.



On Thu, May 18, 2017 at 4:48 PM,  <mark.reinhold at> wrote:
> Over time, as we've gotten closer and closer to the JDK 9 GA date, more
> and more developers have begun paying attention the actual changes in
> this release.  The strong encapsulation of JDK-internal APIs has, in
> particular, triggered many worried expressions of concern that code that
> works on JDK 8 today will not work on JDK 9 tomorrow, yet no advance
> warning of this change was given in JDK 8.
> To help the entire ecosystem migrate to the modular Java platform at a
> more relaxed pace I hereby propose to allow illegal reflective access
> from code on the class path by default in JDK 9, and to disallow it in
> a future release.
> In short, the existing "big kill switch" of the `--permit-illegal-access`
> option [1] will become the default behavior of the JDK 9 run-time system,
> though without as many warnings.  The current behavior of JDK 9, in which
> illegal reflective-access operations from code on the class path are not
> permitted, will become the default in a future release.  Nothing will
> change at compile time.
> In detail, the recently-introduced `--permit-illegal-access` option will
> be replaced by a more-general option, `--illegal-access`.  This option
> will take a single keyword parameter, as follows:
>   `--illegal-access=permit`
>     This will be the default mode for JDK 9.  It opens every package in
>     every explicit module to code in all unnamed modules, i.e., code on
>     the class path, just as `--permit-illegal-access` does today.
>     The first illegal reflective-access operation causes a warning to be
>     issued, as with `--permit-illegal-access`, but no warnings are issued
>     after that point.  This single warning will describe how to enable
>     further warnings.
>   `--illegal-access=warn`
>     This causes a warning message to be issued for each illegal
>     reflective-access operation.  This is equivalent to the current
>     `--permit-illegal-access` option.
>   `--illegal-access=debug`
>     This causes both a warning message and a stack trace to be shown
>     for each illegal reflective-access operation.  This is equivalent
>     to combining today's `--permit-illegal-access` option with
>     `-Dsun.reflect.debugModuleAccessChecks`.
>   `--illegal-access=deny`
>     This disables all illegal reflective-access operations except for
>     those enabled by other command-line options, such as `--add-opens`.
>     This will become the default mode in a future release.
> Notes:
>   - The proposed default mode enables the run-time system to issue a
>     warning message, possibly at some time long after startup, without
>     having been explicitly requested to do so.  This may be a surprise
>     in production environments, since it's extremely unusual for the
>     run-time system to issue any warning messages at all.  If the default
>     mode permits illegal reflective access, however, then it's essential
>     to make that known so that people aren't surprised when this is no
>     longer the default mode in a future release.
>   - Warning messages in any mode can be avoided, as before, by the
>     judicious use of the `--add-exports` and `--add-opens` options.
>   - This proposal will, if adopted, require adjustments to JEP 260,
>     "Encapsulate Most Internal APIs" [2].  APIs that are internal to the
>     JDK will still be strongly encapsulated from the standpoint of code
>     in modules, whether those modules are automatic or explicit, but they
>     will not appear to be encapsulated at run time from the standpoint of
>     code on the class path.
>   - When `deny` becomes the default mode then I expect `permit` to remain
>     supported for at least one release, so that developers can continue
>     to migrate their code.  The `permit`, `warn`, and `debug` modes will,
>     over time, be removed, as will the `--illegal-access` option itself.
>     (For launch-script compatibility the unsupported modes will most
>     likely just be ignored, after issuing a warning to that effect.)
>   - This change will not magically solve every JDK 9 adoption problem.
>     The concrete types of the built-in class loaders are still different,
>     `rt.jar` is still gone, the layout of a system image is still not the
>     same, and the version string still has a new format.
> Comments?
> - Mark
> [1]
> [2]

More information about the jigsaw-dev mailing list