Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unrecognized option: --add-exports / --add-opens #728

Open
bowensong opened this issue Jul 23, 2024 · 2 comments
Open

Unrecognized option: --add-exports / --add-opens #728

bowensong opened this issue Jul 23, 2024 · 2 comments

Comments

@bowensong
Copy link
Contributor

bowensong commented Jul 23, 2024

On newer JDK versions, the options --add-exports and --add-opens are sometimes needed to break the encapsulation. See https://openjdk.org/jeps/261

This works with the java command:

$ java --add-exports java.base/jdk.internal.misc=ALL-UNNAMED --add-opens java.base/java.lang.module=ALL-UNNAMED -version
openjdk version "11.0.22" 2024-01-16
OpenJDK Runtime Environment (build 11.0.22+7-post-Debian-1deb11u1)
OpenJDK 64-Bit Server VM (build 11.0.22+7-post-Debian-1deb11u1, mixed mode, sharing)

However, this doesn't work with pyjnius:

$ cat test.py
import jnius_config
jnius_config.add_options(
    '--add-exports', 'java.base/jdk.internal.misc=ALL-UNNAMED',
    '--add-opens', 'java.base/java.lang.module=ALL-UNNAMED',
)
import jnius

$ python test.py
Unrecognized option: --add-exports
Traceback (most recent call last):
  File "/path/to/test.py", line 6, in <module>
    import jnius
  File "/path/to/ve/lib/python3.9/site-packages/jnius/__init__.py", line 45, in <module>
    from .reflect import *  # noqa
  File "/path/to/ve/lib/python3.9/site-packages/jnius/reflect.py", line 19, in <module>
    class Class(JavaClass, metaclass=MetaJavaClass):
  File "jnius/jnius_export_class.pxi", line 117, in jnius.MetaJavaClass.__new__
  File "jnius/jnius_export_class.pxi", line 177, in jnius.MetaJavaClass.resolve_class
  File "jnius/jnius_env.pxi", line 11, in jnius.get_jnienv
  File "jnius/jnius_jvm_dlopen.pxi", line 95, in jnius.get_platform_jnienv
  File "jnius/jnius_jvm_dlopen.pxi", line 87, in jnius.create_jnienv
SystemError: JVM failed to start: -1

This was tested with pyjnius 1.6.1 on Python 3.9.2 with openjdk-11-jdk 11.0.22u7 on Debian 11.

@bowensong
Copy link
Contributor Author

I found this after some digging around.

The module related options, --add-reads, --add-exports, --add-opens, --add-modules, --limit-modules, --module-path, --patch-module, and --upgrade-module-path must be passed as option strings using their “option=value” format instead of their “option value” format. (Note the required = between “option” and “value”.) For example, to export java.management/sun.management to ALL-UNNAMED pass option string "--add-exports=java.management/sun.management=ALL-UNNAMED".

The code below works fine in pyjnius:

import jnius_config
jnius_config.add_options(
    '--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED',
    '--add-opens=java.base/java.lang.module=ALL-UNNAMED',
)
import jnius

I believe this should be documented here, and the add_options() method should warn the user about it if the options contains any of the --add-reads, --add-exports, --add-opens, --add-modules, --limit-modules, --module-path, --patch-module, and --upgrade-module-path in the unsupported format.

@cmacdonald
Copy link
Contributor

Can you make a PR for the maintainers?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants