question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mongo: Class Not Found jnr.unixsocket.UnixSocket when running in Native

See original GitHub issue

Describe the bug We have a project that uses a lot of Quarkus extensions at the same time. One of these extensions is Mongo Panache and seems to be an incompatibility because when compiling the project in JVM, it works, but not in Native with the following error:

[002-quarkus-all-extensions-1.0.0-SNAPSHOT-runner:24]    classlist:  45.993,33 ms,  1,96 GB
[002-quarkus-all-extensions-1.0.0-SNAPSHOT-runner:24]        setup:   3.249,06 ms,  1,96 GB
Fatal error:java.lang.NoClassDefFoundError
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
	at java.base/java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:603)
	at java.base/java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1006)
	at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:488)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:370)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:529)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:119)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:561)
Caused by: java.lang.NoClassDefFoundError: jnr/unixsocket/UnixSocket
	at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
	at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3166)
	at java.base/java.lang.Class.getDeclaredMethods(Class.java:2309)
	at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleDeletedClass(AnnotationSubstitutionProcessor.java:512)
	at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleClass(AnnotationSubstitutionProcessor.java:305)
	at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.init(AnnotationSubstitutionProcessor.java:265)
	at com.oracle.svm.hosted.NativeImageGenerator.createDeclarativeSubstitutionProcessor(NativeImageGenerator.java:929)
	at com.oracle.svm.hosted.NativeImageGenerator.setupNativeImage(NativeImageGenerator.java:863)
	at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:561)
	at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:476)
	at java.base/java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1407)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
Caused by: java.lang.ClassNotFoundException: jnr.unixsocket.UnixSocket
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	... 16 more

Note that when using only Mongo Panache, it works fine. I could not identify what other extension is causing Mongo to fail with this missing class.

Expected behavior The project should work fine regardless the number of Quarkus extensions we’re using.

Actual behavior It fails to compile, see exception above.

To Reproduce 1- git clone https://github.com/Sgitario/beefy-scenarios 2- git checkout reproducer_15434 3- cd beefy-scenarios/002-quarkus-all-extensions 4- mvn clean verify -Dquarkus.native.builder-image=quay.io/quarkus/ubi-quarkus-native-image:21.0.0-java11 -Dnative -Dquarkus.native.container-build=true (it needs to have built quarkus master locally)

Environment (please complete the following information):

  • Quarkus version or git rev: 999-SNAPSHOT (1.12.1.Final)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:29 (28 by maintainers)

github_iconTop GitHub Comments

1reaction
loicmathieucommented, Mar 4, 2021

@Sgitario as a workaround you can include the jnr library or add the --allow-incomplete-class-path flag to native.

I will work on a substitution to fix the issue, I don’t want to always include this dependency.

0reactions
Sgitariocommented, Jun 9, 2021

I’ve confirmed that this is indeed fixed. Thanks a lot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

GraalVM: Quarkus + Mongo cannot find class - Stack Overflow
NativeImagePhase] Running Quarkus native-image plugin on OpenJDK ... NoClassDefFoundError: jnr/unixsocket/UnixSocketAddress at sun.misc.
Read more >
[JAVA-163] Support Unix Domain Sockets - MongoDB Jira
It requires jnr-unixsocket, but it keeps it an optional dependency; It does not require the installation of additional native libraries ...
Read more >
Could not initialize class jnr.unixsocket.Native$LibC - JRuby
Hello, I'm trying to use the dalli gem (1.1.5) with UNIX sockets under JRuby 1.7.4 on Fedora 19. I get the following error....
Read more >
Unix Domain Socket • Alpakka Documentation
The connector uses JNI and so there are no native dependencies. The binding and connecting APIs are extremely similar to the Tcp Akka...
Read more >
What's New - GitHub Pages
Compatibility with MongoDB 5.1 and support for Java 17 ... The 3.7 driver adds support for Unix domain sockets via the jnr.unixsocket library....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found