quarkus: Native image creation fails with java.lang.NoClassDefFoundError: com/sun/jna/LastErrorException

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.

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 1
  • Comments: 17 (11 by maintainers)

Most upvoted comments

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>

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.

An explanation of why this is happening can be found in https://github.com/oracle/graal/issues/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.