Running application with Java 9, module java.base does not "opens java.io"
Asked Answered
S

3

19

I tried to run my application (front-end developed in Java Swing, server developed with EJB deployed on Wildfly 8) with Java 9. When the client tries to establish an EJB connection got the following exception:

    09:53:42,358 INFO  [xnio] XNIO version 3.2.0.Final
09:53:42,465 INFO  [nio] XNIO NIO Implementation Version 3.2.0.Final
09:53:42,507 DEBUG [nio] Started channel thread 'Remoting "config-based-naming-client-endpoint" I/O-1', selector sun.nio.ch.WindowsSelectorImpl@4b4a5caf
RmiServiceFactpry ExceptionInInitializerError
java.lang.ExceptionInInitializerError
    at org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver.<init>(RemotingConnectionEJBReceiver.java:148)
    at org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver.<init>(RemotingConnectionEJBReceiver.java:106)
    at org.jboss.ejb.client.EJBClientContext.registerConnection(EJBClientContext.java:465)
    at org.jboss.naming.remote.client.ejb.RemoteNamingStoreEJBClientHandler.associate(RemoteNamingStoreEJBClientHandler.java:78)
    at org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1.<init>(RemoteNamingStoreV1.java:71)
    at org.jboss.naming.remote.protocol.v1.VersionOne.getRemoteNamingStore(VersionOne.java:50)
    at org.jboss.naming.remote.protocol.Versions.getRemoteNamingStore(Versions.java:55)
    at org.jboss.naming.remote.client.RemoteContextFactory.createVersionedStore(RemoteContextFactory.java:73)
    at org.jboss.naming.remote.client.HaRemoteNamingStore.failOverSequence(HaRemoteNamingStore.java:202)
    at org.jboss.naming.remote.client.HaRemoteNamingStore.namingStore(HaRemoteNamingStore.java:149)
    at org.jboss.naming.remote.client.HaRemoteNamingStore.namingOperation(HaRemoteNamingStore.java:130)
    at org.jboss.naming.remote.client.HaRemoteNamingStore.lookup(HaRemoteNamingStore.java:272)
    at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:79)
    at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:83)
    at java.naming/javax.naming.InitialContext.lookup(Unknown Source)
    at com.dataloy.client.core.RmiServiceFactory.createRemote(RmiServiceFactory.java:105)
    at com.dataloy.client.core.RmiServiceFactory.getServiceImpl(RmiServiceFactory.java:96)
    at com.dataloy.core.AbstractServiceFactory.getService(AbstractServiceFactory.java:58)
    at com.dataloy.DataloyEngine.getService(DataloyEngine.java:198)
    at com.dataloy.DataloyEngine.login(DataloyEngine.java:548)
    at com.dataloy.client.login.LoginPanel.doLogin(LoginPanel.java:511)
    at com.dataloy.client.login.LoginPanel.access$500(LoginPanel.java:56)
    at com.dataloy.client.login.LoginPanel$5.run(LoginPanel.java:452)
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make java.io.OptionalDataException(boolean) accessible: module java.base does not "opens java.io" to unnamed module @312002a1
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(Unknown Source)
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(Unknown Source)
    at java.base/java.lang.reflect.Constructor.checkCanSetAccessible(Unknown Source)
    at java.base/java.lang.reflect.Constructor.setAccessible(Unknown Source)
    at org.jboss.marshalling.Marshalling$OptionalDataExceptionCreateAction$1.run(Marshalling.java:385)
    at org.jboss.marshalling.Marshalling$OptionalDataExceptionCreateAction$1.run(Marshalling.java:381)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at org.jboss.marshalling.Marshalling$OptionalDataExceptionCreateAction.<init>(Marshalling.java:381)
    at org.jboss.marshalling.Marshalling$OptionalDataExceptionCreateAction.<init>(Marshalling.java:376)
    at org.jboss.marshalling.Marshalling.<clinit>(Marshalling.java:374)
    ... 23 more

I see there is some problem with the new module management introduced in Java 9, but I cannot understand what should do.

Regards, Andrea

Stephie answered 8/3, 2017 at 9:43 Comment(1)
Try to add --add-opens java.base/java.io=ALL-UNNAMED to the java command line to open the java.io package for reflection. Background: mail.openjdk.java.net/pipermail/jdk9-dev/2016-November/…Agential
Q
15

As per this answer you need to add --add-opens java.base/java.io=ALL-UNNAMED to the java command that launches the application.

Quintessa answered 8/3, 2017 at 15:44 Comment(0)
S
9

Adding the following JVM parameters:

--add-exports=java.base/sun.nio.ch=ALL-UNNAMED
--add-opens=java.base/java.lang=ALL-UNNAMED
--add-opens=java.base/java.lang.reflect=ALL-UNNAMED
--add-opens=java.base/java.io=ALL-UNNAMED
--add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED

the above exception it is not reached anymore, it fails before with this exception:

java.lang.ClassNotFoundException: com.dataloy.client.Main
    at jdk.deploy@9-ea/com.sun.deploy.security.DeployURLClassLoader.findClass(Unknown Source)
    at jdk.javaws@9-ea/com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
    at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
    at jdk.javaws@9-ea/com.sun.jnlp.JNLPClassLoader.loadClass(Unknown Source)
    at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
    at jdk.javaws@9-ea/com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
    at jdk.javaws@9-ea/com.sun.javaws.Launcher.run(Unknown Source)
    at java.base/java.lang.Thread.run(Unknown Source)

I need to make visible more modules but I struggling to understand which one.

Andrea

Stephie answered 10/3, 2017 at 11:29 Comment(0)
S
1

I had the same problem before and I solve it, you can check this answer : https://mcmap.net/q/355269/-unable-to-make-field-private-final-java-lang-string-java-io-file-path-accessible

Strop answered 9/5, 2023 at 9:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.