Using Ignite on JDK 9
Asked Answered
C

1

5

I am having trouble using Ignite on JDK 9. I have the following minimal testcase:

package no.ovstetun.ignite;

import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.junit.Test;

public class FailingIgniteTest {
    @Test
    public void failingIgnite() {
        TcpDiscoverySpi discoverySpi = new TcpDiscoverySpi();
    }
}

This code sample fails with the following stacktrace:

java.lang.ExceptionInInitializerError
  at org.apache.ignite.internal.util.IgniteUtils.<clinit>(IgniteUtils.java:769)
  at org.apache.ignite.spi.IgniteSpiAdapter.<init>(IgniteSpiAdapter.java:119)
  at org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi.<init>(TcpDiscoverySpi.java:231)
  at no.nrk.mdb.common.infrastructure.ignite.IgniteConfigurationTest.failingIgnite(IgniteConfigurationTest.java:10)
  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.base/java.lang.reflect.Method.invoke(Method.java:564)
  at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
  at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
  at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
  at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
  at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
  at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
  at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
  at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
  at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
  at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
  at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
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)
  ... 26 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 @31ef45e3
  at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:361)
  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)
  ... 27 more

I am trying to migrate my codebase beyond Java 8, and Ignite is now the only dependency holding me back. I have tried adding --add-module to my runner, but I can't seem to find what is needed to make Ignite work with JDK 9.

The same error is with Ignite versions 2.4.0 and 2.5.0.

Any help would be much appreciated!

Curriculum answered 1/6, 2018 at 8:46 Comment(0)
B
9

Try adding the following parameters when launching Java:

--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED
--add-exports=java.base/sun.nio.ch=ALL-UNNAMED 
Binetta answered 1/6, 2018 at 9:14 Comment(8)
Thanks, that works. Any way to achive the same without using vm-parameters when starting java?Duster
Ignite should not be hacking into JDK internals in jdk.internal.misc, it's too fragile. Someone should make sure there is a bug in Ignite's issue tracker for this.Midday
@AlanBateman How else would you access off-heap memory, which is the fundamental thing for a memory grid?Binetta
Off-heap libraries use sun.misc.Unsafe, they should not be hacking into jdk.internal.misc.Midday
@AlanBateman JavaNioAccess is used by Apache Ignite. What would you replace it with?Binetta
The Ignite maintainers need to fix this, it's impossible to make recommendations here without seeing what they are doing.Midday
@Binetta What's wrong with calling DirectByteBuffer constructor directly? Why do they need to call it via JavaNioAccess?Woodley
ByteBuffer.allocateDirect and wrapping an existing region of memory with JNI NewDirectByteBuffer are the supported ways to create a direct buffer.Midday

© 2022 - 2024 — McMap. All rights reserved.