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 creation fails with java.lang.NoClassDefFoundError: com/sun/jna/LastErrorException #6327

Closed
michael-schnell opened this issue Dec 23, 2019 · 21 comments
Labels
kind/bug Something isn't working triage/needs-feedback We are waiting for feedback.

Comments

@michael-schnell
Copy link
Contributor

michael-schnell commented Dec 23, 2019

Using the "quarkus-jdbc-postgresql" extension fails with the below error. Changing the database to "quarkus-jdbc-mariadb" fixes the problem. So it seems clearly to be related only to the postgresql extension.

[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildStep] /home/developer/.sdkman/candidates/java/19.2.1-grl/jre/bin/native-image -J-DCoordinatorEnvironmentBean.transactionStatusManagerEnable=false -J-Dsun.nio.ch.maxUpdateArraySize=100 -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -J-Dvertx.logger-delegate-factory-class-name=io.quarkus.vertx.core.runtime.VertxLogDelegateFactory -J-Dvertx.disableDnsResolver=true -J-Dio.netty.leakDetection.level=DISABLED -J-Dio.netty.allocator.maxOrder=1 --report-unsupported-elements-at-runtime --initialize-at-build-time= -H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy$BySpaceAndTime -jar cqrs4j-quarkus-example-query-1.0-SNAPSHOT-runner.jar -J-Djava.util.concurrent.ForkJoinPool.common.parallelism=1 -H:FallbackThreshold=0 -H:+ReportExceptionStackTraces -H:-AddAllCharsets -H:EnableURLProtocols=http,https --enable-all-security-services -H:NativeLinkerOption=-no-pie -H:+JNI --no-server -H:-UseServiceLoaderFeature -H:+StackTrace cqrs4j-quarkus-example-query-1.0-SNAPSHOT-runner
[cqrs4j-quarkus-example-query-1.0-SNAPSHOT-runner:5066]    classlist:  20,928.90 ms
[cqrs4j-quarkus-example-query-1.0-SNAPSHOT-runner:5066]        setup:   2,172.90 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:461)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:310)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:448)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:113)
Caused by: java.lang.NoClassDefFoundError: com/sun/jna/LastErrorException
	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
	at java.lang.Class.getDeclaredMethods(Class.java:1975)
	at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleDeletedClass(AnnotationSubstitutionProcessor.java:437)
	at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleClass(AnnotationSubstitutionProcessor.java:270)
	at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.init(AnnotationSubstitutionProcessor.java:230)
	at com.oracle.svm.hosted.NativeImageGenerator.createDeclarativeSubstitutionProcessor(NativeImageGenerator.java:875)
	at com.oracle.svm.hosted.NativeImageGenerator.setupNativeImage(NativeImageGenerator.java:824)
	at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:524)
	at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:444)
	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)
Error: Image build request failed with exit status 1

Expected behavior
Native image creation should work with "quarkus-jdbc-postgresql" as it does with "quarkus-jdbc-mariadb".

Actual behavior
Native image creation fails with "--report-unsupported-elements-at-runtime" and also without this parameter for "quarkus-jdbc-postgresql". Same project setup works fine with "quarkus-jdbc-mariadb".

To Reproduce
Steps to reproduce the behavior:

  1. Checkout project ddd-cqrs-4-java-example
  2. Change two files in quarkus module to use "postgres" instead of mariadb: "pom.xml" and "src/main/resources/application.properties" (See lines commented out)
  3. Follow the instructions in README.md: "Prerequisites" + "Getting started"
  4. Executing "./mvnw verify -Pnative -DskipTests" in module query will fail with above error

Environment (please complete the following information):

  • VMware image with Ubuntu Bionic (Kernel 4.15.0-72-generic, x86_64, 8 GB memory)
  • openjdk version "1.8.0_232"
  • OpenJDK Runtime Environment (build 1.8.0_232-20191008104205.buildslave.jdk8u-src-tar--b07)
  • OpenJDK 64-Bit GraalVM CE 19.2.1 (build 25.232-b07-jvmci-19.2-b03, mixed mode)
  • Quarkus 1.0.1.Final

Additional context
There was a similar issue #796, but I do not use the "shamrock-maven-plugin" as mentioned in that old issue.

@wfrank2509
Copy link

Not sure if it helps - having the same issue - I could narrow it down to make it work when I don't use the Postgres extended types from 'com.vladmihalcea:hibernate-types-52' library.

For me adding this dependency breaks the native build.

@gsmet
Copy link
Member

gsmet commented Feb 2, 2020

@michael-schnell could you try with the latest 1.2.0.Final and GraalVM 19.3.1?

@michael-schnell
Copy link
Contributor Author

michael-schnell commented Feb 2, 2020

@gsmet Unfortunately problem stays the same with Quarkus 1.2.0.Final and GraalVM 19.3.1

[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildStep] Running Quarkus native-image plugin on GraalVM Version 19.3.1 CE
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildStep] /home/developer/.sdkman/candidates/java/19.3.1.r11-grl/bin/native-image -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -J-Dsun.nio.ch.maxUpdateArraySize=100 -J-DCoordinatorEnvironmentBean.transactionStatusManagerEnable=false -J-Dvertx.logger-delegate-factory-class-name=io.quarkus.vertx.core.runtime.VertxLogDelegateFactory -J-Dvertx.disableDnsResolver=true -J-Dio.netty.leakDetection.level=DISABLED -J-Dio.netty.allocator.maxOrder=1 --report-unsupported-elements-at-runtime --initialize-at-build-time= -H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy$BySpaceAndTime -jar cqrs4j-quarkus-example-query-0.1.0-runner.jar -H:FallbackThreshold=0 -H:+ReportExceptionStackTraces -H:-AddAllCharsets -H:EnableURLProtocols=http,https --enable-all-security-services -H:NativeLinkerOption=-no-pie -H:+JNI --no-server -H:-UseServiceLoaderFeature -H:+StackTrace cqrs4j-quarkus-example-query-0.1.0-runner
[cqrs4j-quarkus-example-query-0.1.0-runner:2293]    classlist:  17,237.36 ms
[cqrs4j-quarkus-example-query-0.1.0-runner:2293]        setup:     664.27 ms
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:462)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:315)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:454)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:115)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:479)
Caused by: java.lang.NoClassDefFoundError: com/sun/jna/LastErrorException
	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:437)
	at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleClass(AnnotationSubstitutionProcessor.java:270)
	at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.init(AnnotationSubstitutionProcessor.java:230)
	at com.oracle.svm.hosted.NativeImageGenerator.createDeclarativeSubstitutionProcessor(NativeImageGenerator.java:876)
	at com.oracle.svm.hosted.NativeImageGenerator.setupNativeImage(NativeImageGenerator.java:825)
	at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:528)
	at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:445)
	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:177)
Error: Image build request failed with exit status 1

As before it works fine with Maria DB settings:

[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildStep] /home/developer/.sdkman/candidates/java/19.3.1.r11-grl/bin/native-image -J-DCoordinatorEnvironmentBean.transactionStatusManagerEnable=false -J-Dsun.nio.ch.maxUpdateArraySize=100 -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -J-Dvertx.logger-delegate-factory-class-name=io.quarkus.vertx.core.runtime.VertxLogDelegateFactory -J-Dvertx.disableDnsResolver=true -J-Dio.netty.leakDetection.level=DISABLED -J-Dio.netty.allocator.maxOrder=1 --report-unsupported-elements-at-runtime --initialize-at-build-time= -H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy$BySpaceAndTime -jar cqrs4j-quarkus-example-query-0.1.0-runner.jar -H:FallbackThreshold=0 -H:+ReportExceptionStackTraces -H:-AddAllCharsets -H:EnableURLProtocols=http,https --enable-all-security-services -H:NativeLinkerOption=-no-pie -H:+JNI --no-server -H:-UseServiceLoaderFeature -H:+StackTrace cqrs4j-quarkus-example-query-0.1.0-runner
[cqrs4j-quarkus-example-query-0.1.0-runner:1546]    classlist:  33,036.71 ms
[cqrs4j-quarkus-example-query-0.1.0-runner:1546]        (cap):   1,694.20 ms
[cqrs4j-quarkus-example-query-0.1.0-runner:1546]        setup:   4,244.82 ms
19:29:55,388 INFO  [org.hib.Version] HHH000412: Hibernate Core {5.4.10.Final}
19:29:55,485 INFO  [org.hib.ann.com.Version] HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
19:29:55,745 INFO  [org.hib.dia.Dialect] HHH000400: Using dialect: org.hibernate.dialect.MariaDB103Dialect
19:30:01,117 INFO  [org.jbo.threads] JBoss Threads version 3.0.0.Final
[cqrs4j-quarkus-example-query-0.1.0-runner:1546]   (typeflow): 217,519.65 ms
[cqrs4j-quarkus-example-query-0.1.0-runner:1546]    (objects):  98,380.03 ms
[cqrs4j-quarkus-example-query-0.1.0-runner:1546]   (features):   1,918.56 ms
[cqrs4j-quarkus-example-query-0.1.0-runner:1546]     analysis: 324,628.66 ms
[cqrs4j-quarkus-example-query-0.1.0-runner:1546]     (clinit):   2,247.76 ms
[cqrs4j-quarkus-example-query-0.1.0-runner:1546]     universe:   8,426.76 ms
[cqrs4j-quarkus-example-query-0.1.0-runner:1546]      (parse):  24,863.46 ms
[cqrs4j-quarkus-example-query-0.1.0-runner:1546]     (inline):  19,743.43 ms
[cqrs4j-quarkus-example-query-0.1.0-runner:1546]    (compile): 109,374.97 ms
[cqrs4j-quarkus-example-query-0.1.0-runner:1546]      compile: 159,464.09 ms
[cqrs4j-quarkus-example-query-0.1.0-runner:1546]        image:   8,031.74 ms
[cqrs4j-quarkus-example-query-0.1.0-runner:1546]        write:   2,511.01 ms
[cqrs4j-quarkus-example-query-0.1.0-runner:1546]      [total]: 541,306.39 ms
[INFO] [io.quarkus.deployment.QuarkusAugmentor] Quarkus augmentation completed in 551381ms

@michael-schnell
Copy link
Contributor Author

michael-schnell commented Feb 2, 2020

@wfrank2509 The library 'com.vladmihalcea:hibernate-types-52' is not in the dependency hierarchy.

@wfrank2509
Copy link

wfrank2509 commented Feb 6, 2020

@wfrank2509 The library 'com.vladmihalcea:hibernate-types-52' is not in the dependency hierarchy.

Hi ... yes sure, but if you want to use Postgres Features like the JSONB type you need a library like that. The one mentioned is very commonly used.

And that breaks when used in native build ...

@gsmet
Copy link
Member

gsmet commented Feb 6, 2020

My understanding is that something is trying to delete the com/sun/jna/LastErrorException from the native image but the class is not there.

You have a lot of dependencies so it's a bit hard to know who. I looked at the Quarkus source code and I don't see anything related to that class.

@dmlloyd any idea how we could debug that one?

@dmlloyd
Copy link
Member

dmlloyd commented Feb 6, 2020

We'd have to start by figuring out what requires JNA. The hibernate-types project doesn't seem to use it so it must come in transitively from something else postgres-related.

@ricmzn
Copy link

ricmzn commented Feb 26, 2020

As a workaround, I've found that you can create the class in your own project, extending it from java.lang.Exception, and then run a clean build. It's not a proper fix, but it's enough to make native-build happy in the meantime if you depend on Postgres + Hibernate. Tested on GraalVM 20.0.0 and Quarkus 1.2.0 on Linux x86_64 (in WSL).

@JohT
Copy link
Contributor

JohT commented Mar 14, 2020

As another workaround, native-image configuration <reportErrorsAtRuntime>true</reportErrorsAtRuntime>
works for me (MacOs 10.13.6, GraalVM 20.0.0 CE, Quarkus 1.3.0.Final),
when I add the following dependencies (version managed by quarkus bom):

<dependency>
	<groupId>jakarta.security.jacc</groupId>
	<artifactId>jakarta.security.jacc-api</artifactId>
</dependency>
<dependency>
	<groupId>net.java.dev.jna</groupId>
	<artifactId>jna</artifactId>
</dependency>

@antonwiens
Copy link

Is there a fix in sight?

@michael-schnell
Copy link
Contributor Author

@antonwiens Are you facing the same problem with your code? Unfortunately I haven't had the time to check the above mentioned workarounds for my project.

@antonwiens
Copy link

antonwiens commented Sep 17, 2020

I face the same problem with my code. When using reportErrorsAtRuntime, suddenly the two mentioned dependencies are required.

EDIT: Quarkus 1.7.3 and Graalvm 20.1.0

@jaikiran
Copy link
Member

Hello @antonwiens, is there a simple application you can share (preferably as a github repo) which reproduces this issue?

@antonwiens
Copy link

I will try to create one.

@ghost
Copy link

ghost commented Feb 8, 2021

Still happening with Quarkus 1.11.1.Final and latest GraalVM 21.1.0-dev.

As mentioned above, adding a dependency for JNA fixes the problem:

<dependency>
	<groupId>net.java.dev.jna</groupId>
	<artifactId>jna</artifactId>
</dependency>

@Sgitario
Copy link
Contributor

Sgitario commented Mar 3, 2021

I could reproduce this issue and I had to add this additional dependency to make it work:

         <dependency>
            <groupId>net.java.dev.jna</groupId>
            <artifactId>jna-platform</artifactId>
            <version>5.3.1</version>
        </dependency>

Note that this dependency is not under quarkus bom, so I had to manually set the version.

@zakkak
Copy link
Contributor

zakkak commented Apr 2, 2021

An explanation of why this is happening can be found in oracle/graal#1725

As explained there:

I think there is some misconception about --report-unsupported-elements-at-runtime and @delete:
We introduced the option --report-unsupported-elements-at-runtime so that developers can delay thinking about some Native Image compatibility issues and make quick progress getting a first image built. But that option fundamentally hides problems at image build time that you actually want to have checked. So --report-unsupported-elements-at-runtime should not be used for any images that you want to use in production.
So if you mark something as @delete (which is of course an internal annotation and not part of our API), you are telling the analysis that it is an error if the annotated code is reachable. But then you want this error reported at run time?

So manually adding the dependencies might work around the issue and might be acceptable for development purposes but production code should not use --report-unsupported-elements-at-runtime.

@geoand
Copy link
Contributor

geoand commented Feb 27, 2024

Is this still an issue?

@geoand geoand added the triage/needs-feedback We are waiting for feedback. label Feb 27, 2024
@michael-schnell
Copy link
Contributor Author

I didn't try it again yet.

@wfrank2509
Copy link

Hi! Not really relevant anymore for me.

@geoand
Copy link
Contributor

geoand commented Apr 2, 2024

Closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working triage/needs-feedback We are waiting for feedback.
Projects
None yet
Development

No branches or pull requests