我正在尝试使用 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 totarget-module
, regardless of module declaration. Thetarget-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 totarget-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/