Apache Ignite IllegalAccessException from GridUnsafe when using Ignite object
Asked Answered
D

3

8

This is all I have in my code. It's just the typical way of using Ignite:

Ignite ignite = Ignition.ignite();

The error message I saw is:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.ignite.internal.util.GridUnsafe$2 (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$2
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

Why am I getting this message, and how can I fix this? I am using Java jdk-10.0.1.

Donelson answered 11/1, 2019 at 5:34 Comment(1)
Possible duplicate of Using Ignite on JDK 9Vaporizer
B
5

This problem comes from the module access control system, introduced in Java 9.

To workaround it, use the following JVM parameters:

--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED
--add-exports=java.base/sun.nio.ch=ALL-UNNAMED
Beatriz answered 11/1, 2019 at 9:23 Comment(2)
This doesn't work anymore on JDK 17. Any ideas? Ignite 2.13.0 claims to support JDK17 but I can't make it run on JDK 17, only JDK 11... the docs are not yet updated for running on JDK 17 from what I can see today.Roy
I found the options that are required to run on JDK 17: github.com/apache/ignite/pull/9849/files (lots of internal APIs are used, not very reliable)Roy
B
1

Add the following arguments to the VM of module

Refer this Running-apache-ignite-on-openjdk-15,-16-and-17

--add-opens=java.base/jdk.internal.misc=ALL-UNNAMED 
--add-opens=java.base/sun.nio.ch=ALL-UNNAMED 
--add-opens=java.base/sun.nio.ch=ALL-UNNAMED 
--add-opens=java.management/com.sun.jmx.mbeanserver=ALL-UNNAMED 
--add-opens=jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED 
--add-opens=java.base/sun.reflect.generics.reflectiveObjects=ALL-UNNAMED 
--add-opens=jdk.management/com.sun.management.internal=ALL-UNNAMED 
--add-opens=java.base/java.io=ALL-UNNAMED 
--add-opens=java.base/java.nio=ALL-UNNAMED 
--add-opens=java.base/java.util=ALL-UNNAMED 
--add-opens=java.base/java.lang=ALL-UNNAMED 
Buffybuford answered 12/10, 2022 at 4:12 Comment(0)
S
0

This answer is intended as an addendum to Denis' excellent answer.

In short, when you see this warning for any Java software (not just Apache Ignite):

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.ignite.internal.util.GridUnsafe$2 (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$2
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. Add JVM arg: --illegal-access=warn
  2. Restart the JVM and watch for illegal access warnings.
  3. For each specific warning about a class, e.g., java.nio.Buffer, find the Java module, e.g., java.base, then add a JVM arg for the module & package: --add-opens=java.base/java.nio=ALL-UNNAMED
  4. Rinse and repeat and until all warnings are removed.
  5. Optionally, remove JVM arg --illegal-access=warn

For Java libraries that make extensive use of "unsafe" Java code (off-heap tricks), you might need to add more than 10 of these JVM args!

Scratchy answered 5/5, 2022 at 5:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.