powered by Jive Software

Class javax.naming.spi.NamingManager (in module java.naming) cannot access class com.sun.jndi.dns.DnsContextFactory (in module jdk.naming.dns) because module jdk.naming.dns does not export com.sun.jndi.dns to module java.naming

Hi,
I´m using Smack 4.3.4 in a Java 11 Quarkus app.

I get this exception and i d’not know how to fix it. Please help.

2020-04-10 13:30:50,514 SEVERE [org.jiv.sma.uti.dns.DNSResolver] (main) Could not construct InitialDirContext: javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.jndi.dns.DnsContextFactory [Root exception is java.lang.IllegalAccessException: class javax.naming.spi.NamingManager (in module java.naming) cannot access class com.sun.jndi.dns.DnsContextFactory (in module jdk.naming.dns) because module jdk.naming.dns does not export com.sun.jndi.dns to module java.naming]
at java.naming/javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:719)
at java.naming/javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:305)
at java.naming/javax.naming.InitialContext.init(InitialContext.java:236)
at java.naming/javax.naming.InitialContext.(InitialContext.java:208)
at java.naming/javax.naming.directory.InitialDirContext.(InitialDirContext.java:130)
at org.jivesoftware.smack.util.dns.javax.JavaxResolver.(JavaxResolver.java:58)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:415)
at org.jivesoftware.smack.SmackInitialization.loadSmackClass(SmackInitialization.java:193)
at org.jivesoftware.smack.SmackInitialization.parseClassesToLoad(SmackInitialization.java:173)
at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:143)
at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:128)
at org.jivesoftware.smack.SmackInitialization.(SmackInitialization.java:93)
at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:93)
at org.jivesoftware.smack.provider.ProviderManager.(ProviderManager.java:122)
at es.upsa.rberjon.scifi.messaging.firebase.messaging.xmpp.server.FcmClient.(FcmClient.java:84)
at es.upsa.rberjon.scifi.messaging.firebase.messaging.xmpp.FirebaseXmppMessageSink.init(FirebaseXmppMessageSink.java:41)
at es.upsa.rberjon.scifi.messaging.firebase.FirebaseConnector.getSubscriberBuilder(FirebaseConnector.java:39)
at es.upsa.rberjon.scifi.messaging.firebase.FirebaseConnector_ClientProxy.getSubscriberBuilder(FirebaseConnector_ClientProxy.zig:52)
at io.smallrye.reactive.messaging.impl.ConfiguredChannelFactory.createSubscriberBuilder(ConfiguredChannelFactory.java:188)
at io.smallrye.reactive.messaging.impl.ConfiguredChannelFactory.lambda$register$5(ConfiguredChannelFactory.java:150)
at java.base/java.util.HashMap.forEach(HashMap.java:1333)
at io.smallrye.reactive.messaging.impl.ConfiguredChannelFactory.register(ConfiguredChannelFactory.java:150)
at io.smallrye.reactive.messaging.impl.ConfiguredChannelFactory.initialize(ConfiguredChannelFactory.java:123)
at io.smallrye.reactive.messaging.impl.ConfiguredChannelFactory_ClientProxy.initialize(ConfiguredChannelFactory_ClientProxy.zig:195)
at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:658)
at io.smallrye.reactive.messaging.extension.MediatorManager.initializeAndRun(MediatorManager.java:156)
at io.smallrye.reactive.messaging.extension.MediatorManager_ClientProxy.initializeAndRun(MediatorManager_ClientProxy.zig:100)
at io.quarkus.smallrye.reactivemessaging.runtime.SmallRyeReactiveMessagingLifecycle.onApplicationStart(SmallRyeReactiveMessagingLifecycle.java:20)
at io.quarkus.smallrye.reactivemessaging.runtime.SmallRyeReactiveMessagingLifecycle_Observer_onApplicationStart_4e8937813d9e8faff65c3c07f88fa96615b70e70.notify(SmallRyeReactiveMessagingLifecycle_Observer_onApplicationStart_4e8937813d9e8faff65c3c07f88fa96615b70e70.zig:51)
at io.quarkus.arc.impl.EventImpl$Notifier.notifyObservers(EventImpl.java:282)
at io.quarkus.arc.impl.EventImpl$Notifier.notify(EventImpl.java:267)
at io.quarkus.arc.impl.EventImpl.fire(EventImpl.java:69)
at io.quarkus.arc.runtime.LifecycleEventRunner.fireStartupEvent(LifecycleEventRunner.java:23)
at io.quarkus.arc.runtime.ArcRecorder.handleLifecycleEvents(ArcRecorder.java:113)
at io.quarkus.deployment.steps.LifecycleEventsBuildStep$startupEvent35.deploy_0(LifecycleEventsBuildStep$startupEvent35.zig:77)
at io.quarkus.deployment.steps.LifecycleEventsBuildStep$startupEvent35.deploy(LifecycleEventsBuildStep$startupEvent35.zig:36)
at io.quarkus.runner.ApplicationImpl.doStart(ApplicationImpl.zig:202)
at io.quarkus.runtime.Application.start(Application.java:90)
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:567)
at io.quarkus.runner.bootstrap.StartupActionImpl.run(StartupActionImpl.java:99)
at io.quarkus.dev.IsolatedDevModeMain.firstStart(IsolatedDevModeMain.java:60)
at io.quarkus.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:236)
at io.quarkus.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:39)
at io.quarkus.bootstrap.app.CuratedApplication.runInCl(CuratedApplication.java:131)
at io.quarkus.bootstrap.app.CuratedApplication.runInAugmentClassLoader(CuratedApplication.java:84)
at io.quarkus.dev.DevModeMain.start(DevModeMain.java:113)
at io.quarkus.dev.DevModeMain.main(DevModeMain.java:54)
Caused by: java.lang.IllegalAccessException: class javax.naming.spi.NamingManager (in module java.naming) cannot access class com.sun.jndi.dns.DnsContextFactory (in module jdk.naming.dns) because module jdk.naming.dns does not export com.sun.jndi.dns to module java.naming
at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:376)
at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:639)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:490)
at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:166)
at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:404)
at java.base/java.lang.Class.newInstance(Class.java:590)
at java.naming/javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:716)
… 52 more

I fix it!!!

When I execute the application, I must add the option --add-exports:

java -jar application.jar --add-exports jdk.naming.dns/com.sun.jndi.dns=java.naming

Thanks.

1 Like

Another alternative would be using the MiniDnsResolver from smack-resolver-minidns.