使用 Ignite 对象时来自 GridUnsafe 的 Apache Ignite IllegalAccessException

Apache Ignite IllegalAccessException from GridUnsafe when using Ignite object

这就是我的代码中的全部内容。这只是 Ignite 的典型使用方式:

Ignite ignite = Ignition.ignite();

我看到的错误信息是:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.ignite.internal.util.GridUnsafe (file:/C:/Users/.../.m2/repository/org/apache/ignite/ignite-core/2.7.0/ignite-core-2.7.0.jar) to field java.nio.Buffer.address
WARNING: Please consider reporting this to the maintainers of org.apache.ignite.internal.util.GridUnsafe
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
Exception in thread "main" java.lang.ExceptionInInitializerError
    at org.apache.ignite.internal.util.IgniteUtils.<clinit>(IgniteUtils.java:795)
    at org.apache.ignite.internal.IgnitionEx.<clinit>(IgnitionEx.java:209)
    at org.apache.ignite.Ignition.ignite(Ignition.java:489)
    at distributedjobexecutor.App.<init>(App.java:19)
    at distributedjobexecutor.App.main(App.java:39)
Caused by: java.lang.RuntimeException: jdk.internal.misc.JavaNioAccess class is unavailable.
    at org.apache.ignite.internal.util.GridUnsafe.javaNioAccessObject(GridUnsafe.java:1453)
    at org.apache.ignite.internal.util.GridUnsafe.<clinit>(GridUnsafe.java:112)
    ... 5 more
Caused by: java.lang.IllegalAccessException: class org.apache.ignite.internal.util.GridUnsafe cannot access class jdk.internal.misc.SharedSecrets (in module java.base) because module java.base does not export jdk.internal.misc to unnamed module @2ac273d3
    at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:360)
    at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:589)
    at java.base/java.lang.reflect.Method.invoke(Method.java:556)
    at org.apache.ignite.internal.util.GridUnsafe.javaNioAccessObject(GridUnsafe.java:1450)
    ... 6 more

为什么我会收到这条消息,我该如何解决?我正在使用 Java jdk-10.0.1.

这个问题来自模块门禁系统,在Java9.

中引入

要解决此问题,请使用以下 JVM 参数:

--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED
--add-exports=java.base/sun.nio.ch=ALL-UNNAMED

此回答旨在作为 Denis 出色回答的补充。

简而言之,当您看到任何 Java 软件(不仅仅是 Apache Ignite)的警告时:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.ignite.internal.util.GridUnsafe (file:/C:/Users/.../.m2/repository/org/apache/ignite/ignite-core/2.7.0/ignite-core-2.7.0.jar) to field java.nio.Buffer.address
WARNING: Please consider reporting this to the maintainers of org.apache.ignite.internal.util.GridUnsafe
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
  1. 添加 JVM 参数:--illegal-access=warn
  2. 重新启动 JVM 并注意非法访问警告。
  3. 对于每个关于 class 的特定警告,例如 java.nio.Buffer,找到 Java 模块,例如 java.base,然后为该模块添加一个 JVM arg &包裹:--add-opens=java.base/java.nio=ALL-UNNAMED
  4. 冲洗并重复,直到删除所有警告。
  5. 可选地,删除 JVM arg --illegal-access=warn

对于广泛使用“不安全”Java 代码(off-heap 技巧)的 Java 库,您可能需要添加超过 10 个这样的 JVM 参数!