java - JDK9 : An illegal reflective access operation has occurred. org.python.core.PySystemState

标签 java java-9 java-module

我正在尝试使用 Java9 (JDK9) 运行 DMelt 程序 (http://jwork.org/dmelt/) 程序,它给了我以下错误:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.python.core.PySystemState (file:/dmelt/jehep/lib/jython/jython.jar) to method java.io.Console.encoding()
WARNING: Please consider reporting this to the maintainers of org.python.core.PySystemState
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

我该如何解决?我试图将 –illegal-access=permit 添加到脚本“dmelt.sh”的最后一行(我在 Linux 中使用 bash),但这并没有解决这个问题。我对此感到非常沮丧。我经常使用这个程序,很长一段时间。也许我永远不应该迁移到 JDK9

最佳答案

解决这个问题的理想方法是

reporting this to the maintainers of org.python.core.PySystemState

并要求他们在未来修复此类反射访问。


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.

来自 threads on the mailing list 之一:

--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=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.

像以前一样,明智地使用 --add-exports 可以避免任何模式下的警告消息。和 --add-opens选项。


因此,当前可用的临时解决方案是使用 --add-exports作为 docs 中提到的 VM 参数:

--add-exports module/package=target-module(,target-module)*

Updates module to export package to target-module, regardless of module declaration. The target-module can be all unnamed to export to all unnamed modules.

这将允许 target-module访问 package 中的所有公共(public)类型.如果您想访问仍将被封装的 JDK 内部类,则必须使用 --add-opens 允许 深度反射论据为:

--add-opens module/package=target-module(,target-module)*

Updates module to open package to target-module, regardless of module declaration.

在您的情况下,当前访问 java.io.Console ,您可以简单地将其添加为 VM 选项 -

--add-opens java.base/java.io=ALL-UNNAMED

另外,请注意上面链接的同一线程

deny成为默认模式,然后我希望 permit至少支持一个版本,以便开发人员可以继续迁移他们的代码。 permit , warn , 和 debug随着时间的推移,模​​式将被删除,--illegal-access 也将被删除。选项本身。

所以最好改变实现并遵循理想的解决方案。

关于java - JDK9 : An illegal reflective access operation has occurred. org.python.core.PySystemState,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46230413/

相关文章:

java - List<Map<String,Object>> 到 org.json.JSONObject?

java - 什么是 JUnit 测试用例?我将如何编写一个测试用例?

java - 用于 Arraylist 处理和调用不同方法的高效 Java 构造

java - 如何使 javadoc 文档在 JShell 中可用?

java - Java 模块指令如何影响对模块的反射访问?

java - spring.core 的这个模块定义有什么问题?

java - 无法转换为类 - 它们位于加载程序 'app' 的未命名模块中

java - Maven 没有将所有依赖项添加到 jar

java - FIRESTORE - 在文档中插入子集合

java - 使用 native API : JVM_LoadClass0, JVM_AllocateNewArray 和 JVM_AllocateNewObject 的替代解决方案