Search code examples
javaignitejava-17

Is there a way to pass JVM arguments when starting Ignite client


I am able to start up my Ignite server on Java 17 by adding some JVM arguments the ignite.sh script but when I startup my Ignite client via Ignition.start or Ignition.startClient I am getting reflection exceptions.

Is there a way to:

  1. Provide additional arguments that will be given when Ignition.start spins up a new jvm process?
  2. If not, is there a way to create a Ignite Client via ignite.sh?

I know these issues could be fixed by using Java 11 but that is not an option.

Below is stack trace I get after calling Ignition.start

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-02-28 18:50:34.518 ERROR 53868 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'igniteThinCacheManager': Invocation of init method failed; nested exception is java.lang.ExceptionInInitializerError
        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:160) ~[spring-beans-5.3.15.jar!/:5.3.15]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:440) ~[spring-beans-5.3.15.jar!/:5.3.15]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796) ~[spring-beans-5.3.15.jar!/:5.3.15]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.15.jar!/:5.3.15]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.15.jar!/:5.3.15]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.15.jar!/:5.3.15]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.15.jar!/:5.3.15]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.15.jar!/:5.3.15]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.15.jar!/:5.3.15]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953) ~[spring-beans-5.3.15.jar!/:5.3.15]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.15.jar!/:5.3.15]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.15.jar!/:5.3.15]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.3.jar!/:2.6.3]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732) ~[spring-boot-2.6.3.jar!/:2.6.3]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:414) ~[spring-boot-2.6.3.jar!/:2.6.3]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) ~[spring-boot-2.6.3.jar!/:2.6.3]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303) ~[spring-boot-2.6.3.jar!/:2.6.3]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292) ~[spring-boot-2.6.3.jar!/:2.6.3]
        at com.niksun.myService.MyServiceApplication.main(MyServiceApplication.java:10) ~[classes!/:0.0.1-SNAPSHOT]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:na]
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:na]
        at java.base/java.lang.reflect.Method.invoke(Unknown Source) ~[na:na]
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[myService-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[myService-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[myService-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88) ~[myService-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
Caused by: java.lang.ExceptionInInitializerError: null
        at org.apache.ignite.internal.util.IgniteUtils.<clinit>(IgniteUtils.java:865) ~[ignite-core-2.12.0.jar!/:2.12.0]
        at org.apache.ignite.internal.client.thin.TcpIgniteClient$ClientMarshallerContext.<init>(TcpIgniteClient.java:542) ~[ignite-core-2.12.0.jar!/:2.12.0]
        at org.apache.ignite.internal.client.thin.TcpIgniteClient.<init>(TcpIgniteClient.java:114) ~[ignite-core-2.12.0.jar!/:2.12.0]
        at org.apache.ignite.internal.client.thin.TcpIgniteClient.<init>(TcpIgniteClient.java:102) ~[ignite-core-2.12.0.jar!/:2.12.0]
        at org.apache.ignite.internal.client.thin.TcpIgniteClient.start(TcpIgniteClient.java:339) ~[ignite-core-2.12.0.jar!/:2.12.0]
        at org.apache.ignite.Ignition.startClient(Ignition.java:615) ~[ignite-core-2.12.0.jar!/:2.12.0]
        at com.niksun.myService.cache.IgniteThinCacheManager.init(IgniteThinCacheManager.java:45) ~[classes!/:0.0.1-SNAPSHOT]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:na]
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:na]
        at java.base/java.lang.reflect.Method.invoke(Unknown Source) ~[na:na]
        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:389) ~[spring-beans-5.3.15.jar!/:5.3.15]
        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:333) ~[spring-beans-5.3.15.jar!/:5.3.15]
        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:157) ~[spring-beans-5.3.15.jar!/:5.3.15]
        ... 26 common frames omitted
Caused by: java.lang.RuntimeException: java.nio.DirectByteBuffer.address field is unavailable.
        at org.apache.ignite.internal.util.GridUnsafe$2.run(GridUnsafe.java:1570) ~[ignite-core-2.12.0.jar!/:2.12.0]
        at org.apache.ignite.internal.util.GridUnsafe$2.run(GridUnsafe.java:1557) ~[ignite-core-2.12.0.jar!/:2.12.0]
        at java.base/java.security.AccessController.doPrivileged(Unknown Source) ~[na:na]
        at org.apache.ignite.internal.util.GridUnsafe.bufferAddressOffset(GridUnsafe.java:1557) ~[ignite-core-2.12.0.jar!/:2.12.0]
        at org.apache.ignite.internal.util.GridUnsafe.<clinit>(GridUnsafe.java:109) ~[ignite-core-2.12.0.jar!/:2.12.0]
        ... 40 common frames omitted
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field long java.nio.Buffer.address accessible: module java.base does not "opens java.nio" to unnamed module @27abe2cd
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(Unknown Source) ~[na:na]
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(Unknown Source) ~[na:na]
        at java.base/java.lang.reflect.Field.checkCanSetAccessible(Unknown Source) ~[na:na]
        at java.base/java.lang.reflect.Field.setAccessible(Unknown Source) ~[na:na]
        at org.apache.ignite.internal.util.GridUnsafe$2.run(GridUnsafe.java:1562) ~[ignite-core-2.12.0.jar!/:2.12.0]
        ... 44 common frames omitted

Edit, to anyone that finds this I was incorrectly passing in the JVM arguments when starting up my spring boot application. Once I fixed that the InaccessibleObjectException no longer occurred.

Below is the list of arguments I used:

        --add-exports=java.base/sun.nio.ch=ALL-UNNAMED
        --add-exports=java.management/com.sun.jmx.mbeanserver=ALL-UNNAMED
        --add-exports=jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED
        --add-exports=java.base/sun.reflect.generics.reflectiveObjects=ALL-UNNAMED
        --add-opens jdk.management/com.sun.management.internal=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

Solution

  • In the end the problem was that I was not properly passing in the jvm arguments. Once I fixed that the application works with Java 17 given the arguments above. I suppose these are no guarantees I wont hit some other snags.