'Apache Ignite IllegalAccessException from GridUnsafe when using Ignite object
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.
Solution 1:[1]
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
Solution 2:[2]
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
- Add JVM arg:
--illegal-access=warn
- Restart the JVM and watch for illegal access warnings.
- 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
- Rinse and repeat and until all warnings are removed.
- 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!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Denis |
Solution 2 | kevinarpe |