JDK-8346778 : Enable native access should work with the source launcher
  • Type: Bug
  • Component: tools
  • Sub-Component: launcher
  • Affected Version: 22,23,24
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2024-12-23
  • Updated: 2025-01-20
  • Resolved: 2025-01-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 25
25 b06Fixed
Description
Enable native access doesn't work with the source launcher if launching in a named module.

```
run:
    java \
      --enable-native-access=dev.mccue.sdl \
      -Djava.library.path=SDL/build \
      -XstartOnFirstThread \
      src/example/Main.java

WARNING: Unknown module: dev.mccue.sdl specified to --enable-native-access

Exception in thread "main" java.lang.ExceptionInInitializerError
    at dev.mccue.sdl/example.Main.main(Main.java:15)
Caused by: java.lang.IllegalCallerException: Illegal native access from: module dev.mccue.sdl

java --enable-native-access=ALL-UNNAMED -Djava.library.path=SDL/build -XstartOnFirstThread src/example/Main.java

Exception in thread "main" java.lang.ExceptionInInitializerError
    at dev.mccue.sdl/example.Main.main(Main.java:15)
Caused by: java.lang.IllegalCallerException: Illegal native access from: module dev.mccue.sdl
```

File tree looks like:

```
src/
  example/
    Main.java
  dev/
    mccue/
      sdl/
        ...
  module-info.java (dev.mccue.sdl)
```

Work-around: remove the `module-info.java` file to make the source launcher load the classes in the unnamend module and pass `--enable-native-access=ALL-UNNAMED` to the launcher as can be seen in the second example.
Comments
Changeset: fec769b0 Branch: master Author: Christian Stein <cstein@openjdk.org> Date: 2025-01-14 10:34:51 +0000 URL: https://git.openjdk.org/jdk/commit/fec769b0a840ca4351e2458c24184ec69c112c09
14-01-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/22930 Date: 2025-01-06 16:35:59 +0000
08-01-2025