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

Enable native access should work with the source launcher

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 25
    • 22, 23, 24
    • tools
    • None
    • b06

      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.

            cstein Christian Stein
            cstein Christian Stein
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: