Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[native-image] NoClassDefFoundError when working with LOG4J2 dependencies #671

Closed
SR-G opened this issue Sep 11, 2018 · 7 comments
Closed
Assignees

Comments

@SR-G
Copy link

SR-G commented Sep 11, 2018

NoClassDefFoundError with some LOG4J2 dependencies.
Simple project allowing to reproduce the issue located here :
https://github.com/SR-G/graalvm-bug-noclassdeffounderror

Bug probably related to #353

Happening with 1.0.0-rc6 :

> native-image --version 
GraalVM Version 1.0.0-rc6

Stacktrace for reference :

[graalvm-bug-noclassdeffounderror-1.0.0-SNAPSHOT:47]    classlist:   3,566.45 ms
[graalvm-bug-noclassdeffounderror-1.0.0-SNAPSHOT:47]        (cap):   2,145.87 ms
[graalvm-bug-noclassdeffounderror-1.0.0-SNAPSHOT:47]        setup:   4,320.70 ms
[graalvm-bug-noclassdeffounderror-1.0.0-SNAPSHOT:47]     analysis:   4,048.34 ms
fatal error: java.lang.NoClassDefFoundError
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:598)
	at java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1005)
	at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:418)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:278)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:375)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:104)
Caused by: java.lang.NoClassDefFoundError
	at jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.lookupType(HotSpotJVMCIRuntime.java:464)
	at jdk.vm.ci.hotspot.HotSpotResolvedObjectTypeImpl.lookupType(HotSpotResolvedObjectTypeImpl.java:957)
	at jdk.vm.ci.meta.UnresolvedJavaType.resolve(UnresolvedJavaType.java:92)
	at jdk.vm.ci.hotspot.HotSpotResolvedJavaFieldImpl.getType(HotSpotResolvedJavaFieldImpl.java:126)
	at com.oracle.graal.pointsto.meta.AnalysisType.<init>(AnalysisType.java:185)
	at com.oracle.graal.pointsto.meta.AnalysisUniverse.createType(AnalysisUniverse.java:251)
	at com.oracle.graal.pointsto.meta.AnalysisUniverse.lookupAllowUnresolved(AnalysisUniverse.java:193)
	at com.oracle.graal.pointsto.meta.AnalysisUniverse.lookup(AnalysisUniverse.java:170)
	at com.oracle.graal.pointsto.meta.AnalysisField.<init>(AnalysisField.java:104)
	at com.oracle.graal.pointsto.meta.AnalysisUniverse.createField(AnalysisUniverse.java:353)
	at com.oracle.graal.pointsto.meta.AnalysisUniverse.lookupAllowUnresolved(AnalysisUniverse.java:341)
	at com.oracle.graal.pointsto.meta.AnalysisUniverse.lookup(AnalysisUniverse.java:308)
	at com.oracle.graal.pointsto.meta.AnalysisType.convertFields(AnalysisType.java:875)
	at com.oracle.graal.pointsto.meta.AnalysisType.convertInstanceFields(AnalysisType.java:868)
	at com.oracle.graal.pointsto.meta.AnalysisType.getInstanceFields(AnalysisType.java:859)
	at com.oracle.graal.pointsto.meta.AnalysisType.convertInstanceFields(AnalysisType.java:866)
	at com.oracle.graal.pointsto.meta.AnalysisType.getInstanceFields(AnalysisType.java:859)
	at com.oracle.graal.pointsto.ObjectScanner.doScan(ObjectScanner.java:268)
	at com.oracle.graal.pointsto.ObjectScanner.finish(ObjectScanner.java:312)
	at com.oracle.graal.pointsto.ObjectScanner.scanBootImageHeapRoots(ObjectScanner.java:81)
	at com.oracle.graal.pointsto.ObjectScanner.scanBootImageHeapRoots(ObjectScanner.java:63)
	at com.oracle.graal.pointsto.BigBang.checkObjectGraph(BigBang.java:591)
	at com.oracle.graal.pointsto.BigBang.finish(BigBang.java:562)
	at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:690)
	at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:401)
	at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: java.lang.ClassNotFoundException: com.lmax.disruptor.dsl.Disruptor
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at jdk.vm.ci.hotspot.CompilerToVM.lookupType(Native Method)
	at jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.lookupType(HotSpotJVMCIRuntime.java:456)
	... 29 more
Error: Image building with exit status 1
@jhult
Copy link
Contributor

jhult commented Sep 19, 2018

I am hitting the same issue.

@jhult
Copy link
Contributor

jhult commented Sep 19, 2018

From https://logging.apache.org/log4j/2.x/manual/async.html

Asynchronous Loggers internally use the Disruptor, a lock-free inter-thread communication library, instead of queues, resulting in higher throughput and lower latency.

You can see this in the sources here.

I can get past this error by adding this dependency to my pom.xml:

<dependency>
    <groupId>com.lmax</groupId>
    <artifactId>disruptor</artifactId>
    <version>3.4.2</version>
    <scope>runtime</scope>
</dependency>

More reading: https://logging.apache.org/log4j/2.x/runtime-dependencies.html#log4j-core

@SR-G
Copy link
Author

SR-G commented Sep 19, 2018

Sure, but this is a runtime dependency, not needed if you don't activate that kind of aync loggers (i don't have it on any of my projects), so should GraalVM generate that kind of errors in this situation ?
If it was a mandatory dependency, it would be declared in LOG4J2's pom as "compile" and not "runtime".

@cstancu
Copy link
Member

cstancu commented Sep 19, 2018

@SR-G is right, you shouldn't have to add dependencies that you don't actually use. However, native-image currently has issues with incomplete class paths leading to errors like the one reported here. We are working on a solution, in the meantime the workaround is to make sure you have a complete classpath, like proposed by @jhult .

@jhult
Copy link
Contributor

jhult commented Oct 30, 2018

@cstancu, any updates on this?

I talked to @christianwimmer at OpenWorld and he indicated a Maven plugin may soon be available to help add all dependencies to the classpath.

This also appears to be related to #749 and #754.

@cstancu
Copy link
Member

cstancu commented Oct 30, 2018

@jhult the incomplete class path support is under testing, ironing out some corner cases. The maven plugin is already available, it was released as part of rc8. See the release notes: A new Maven plugin allows native image generation from within a Maven build. However this plugin makes it easier to manage your project dependency on SubstrateVM, but it doesn't manage your other dependencies.

@sdeleuze
Copy link
Collaborator

This issue is fixed by --allow-incomplete-classpath and superseeded by #808.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants