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

Created on 23 Dec 2019  路  14Comments  路  Source: quarkusio/quarkus

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.

kinbug

Most helpful comment

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>

All 14 comments

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.

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

@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

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

@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 ...

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?

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.

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).

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>

Is there a fix in sight?

@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.

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

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

I will try to create one.

Was this page helpful?
0 / 5 - 0 ratings