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 building problem using 2.0.0.CR2 version #17552

Closed
mrniko opened this issue May 31, 2021 · 12 comments
Closed

Native-image building problem using 2.0.0.CR2 version #17552

mrniko opened this issue May 31, 2021 · 12 comments
Assignees
Labels
area/native-image kind/bug Something isn't working triage/invalid This doesn't seem right

Comments

@mrniko
Copy link

mrniko commented May 31, 2021

Describe the bug

Getting error below during native-image building.

[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildStep] Building native image from /var/tmp/quarkus-redisson-client/integration-tests/target/quarkus-redisson-client-integration-tests-1.0.0-SNAPSHOT-native-image-source-jar/quarkus-redisson-client-integration-tests-1.0.0-SNAPSHOT-runner.jar
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildStep] Running Quarkus native-image plugin on GraalVM 21.1.0 Java 11 CE (Java Version 11.0.11+8-jvmci-21.1-b05)
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildRunner] /opt/graalvm-ce-java11-21.1.0/bin/native-image -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -J-Dsun.nio.ch.maxUpdateArraySize=100 -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=3 -J-Duser.language=en -J-Duser.country=US -J-Dfile.encoding=UTF-8 --report-unsupported-elements-at-runtime --allow-incomplete-classpath --initialize-at-build-time= -H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy\$BySpaceAndTime -H:+JNI -H:+AllowFoldMethods -jar quarkus-redisson-client-integration-tests-1.0.0-SNAPSHOT-runner.jar -H:FallbackThreshold=0 -H:+ReportExceptionStackTraces -H:-AddAllCharsets -H:EnableURLProtocols=http,https -H:NativeLinkerOption=-no-pie -H:-UseServiceLoaderFeature -H:+StackTrace quarkus-redisson-client-integration-tests-1.0.0-SNAPSHOT-runner
[quarkus-redisson-client-integration-tests-1.0.0-SNAPSHOT-runner:25784]    classlist:   4,099.87 ms,  1.19 GB
[quarkus-redisson-client-integration-tests-1.0.0-SNAPSHOT-runner:25784]        setup:     609.23 ms,  1.19 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:499)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:370)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:531)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:119)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:568)
Caused by: java.lang.NoClassDefFoundError: Lcom/aayushatharva/brotli4j/decoder/DecoderJNI$Wrapper;
        at java.base/java.lang.Class.getDeclaredFields0(Native Method)
        at java.base/java.lang.Class.privateGetDeclaredFields(Class.java:3061)
        at java.base/java.lang.Class.getDeclaredFields(Class.java:2248)
        at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleDeletedClass(AnnotationSubstitutionProcessor.java:531)
        at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleClass(AnnotationSubstitutionProcessor.java:306)
        at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.init(AnnotationSubstitutionProcessor.java:266)
        at com.oracle.svm.hosted.NativeImageGenerator.createDeclarativeSubstitutionProcessor(NativeImageGenerator.java:954)
        at com.oracle.svm.hosted.NativeImageGenerator.setupNativeImage(NativeImageGenerator.java:888)
        at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:580)
        at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$2(NativeImageGenerator.java:495)
        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: com.aayushatharva.brotli4j.decoder.DecoderJNI$Wrapper
        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

(Describe the problem clearly and concisely.)

Expected behavior

Native-image built successfully.

Actual behavior

Unable to build native-image.

To Reproduce

Run attached project.
quarkus-redisson-client.zip

mvn clean integration-test -Dnative=true

Environment (please complete the following information):

Output of uname -a or ver

Linux 3bc459ae2770 4.9.93-linuxkit-aufs #1 SMP Wed Jun 6 16:55:56 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment GraalVM CE 21.1.0 (build 11.0.11+8-jvmci-21.1-b05)
OpenJDK 64-Bit Server VM GraalVM CE 21.1.0 (build 11.0.11+8-jvmci-21.1-b05, mixed mode, sharing)

Quarkus version or git rev

2.0.0.CR2

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 11.0.11, vendor: GraalVM Community, runtime: /opt/graalvm-ce-java11-21.1.0
Default locale: en_US, platform encoding: ANSI_X3.4-1968
OS name: "linux", version: "4.9.93-linuxkit-aufs", arch: "amd64", family: "unix"

@mrniko mrniko added the kind/bug Something isn't working label May 31, 2021
@mrniko
Copy link
Author

mrniko commented May 31, 2021

Building successfully with 1.13.6.Final.

@geoand
Copy link
Contributor

geoand commented May 31, 2021

cc @zakkak

@zakkak zakkak self-assigned this May 31, 2021
@zakkak
Copy link
Contributor

zakkak commented May 31, 2021

TLDR: Please remove --report-unsupported-elements-at-runtime from integration-tests/pom.xml.

This is similar to #6327. The reason the example is not working any more is the deletion of io.netty.handler.codec.compression.BrotliDecoder which was introduced by #17436 and is not compatible with --report-unsupported-elements-at-runtime.

@mrniko
Copy link
Author

mrniko commented Jun 1, 2021

I removed --report-unsupported-elements-at-runtime. Now I see another error, which is not appear with 1.13.6.Final

Error: could not find target field: private java.net.InetAddress io.quarkus.redisson.client.runtime.graal.InternetProtocolFamilySubstitutions.localHost
com.oracle.svm.core.util.UserError$UserException: could not find target field: private java.net.InetAddress io.quarkus.redisson.client.runtime.graal.InternetProtocolFamilySubstitutions.localHost
        at com.oracle.svm.core.util.UserError.abort(UserError.java:68)
        at com.oracle.svm.core.util.UserError.guarantee(UserError.java:96)
        at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.findOriginalField(AnnotationSubstitutionProcessor.java:780)
        at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleFieldInAliasClass(AnnotationSubstitutionProcessor.java:440)
        at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleAliasClass(AnnotationSubstitutionProcessor.java:344)
        at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleClass(AnnotationSubstitutionProcessor.java:310)
        at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.init(AnnotationSubstitutionProcessor.java:266)
        at com.oracle.svm.hosted.NativeImageGenerator.createDeclarativeSubstitutionProcessor(NativeImageGenerator.java:954)
        at com.oracle.svm.hosted.NativeImageGenerator.setupNativeImage(NativeImageGenerator.java:888)
        at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:580)
        at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$2(NativeImageGenerator.java:495)
        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)

@zakkak
Copy link
Contributor

zakkak commented Jun 1, 2021

In runtime/src/main/java/io/quarkus/redisson/client/runtime/graal/NettySubstitutions.java you are injecting some accessors to io.netty.channel.socket.InternetProtocolFamily's localHost field, however this field is no longer available in Netty 4.1.65.Final which is the one used in Quarkus 2.0.0.CR2. So you will need to update or remove the NettySubstitutions class.

@mrniko
Copy link
Author

mrniko commented Jun 1, 2021

@zakkak
Copy link
Contributor

zakkak commented Jun 1, 2021

@mrniko
Copy link
Author

mrniko commented Jun 1, 2021

InternetProtocolFamily has public InetAddress localhost() method even in netty 4.1.49.Final version.

@zakkak
Copy link
Contributor

zakkak commented Jun 1, 2021

In your code you are not substituting the method localhost() but the field localHost which exists in 4.1.49.Final but not in 4.1.65.Final. So when you try to compile the example with 2.0.0.CR2 GraalVM fails to find the field.

@mrniko
Copy link
Author

mrniko commented Jun 2, 2021

Sorry, my mistake. I fixed that, but now I'm getting this error:

Error: Already registered: io.netty.util.NetUtil.LOCALHOST4
com.oracle.svm.core.util.UserError$UserException: Already registered: io.netty.util.NetUtil.LOCALHOST4

Seems quarkus 2.0.0 has own NetUtil substitution. I would like to keep backward compatibility with previous versions. Do you know how to handle that?

Updated project:
quarkus-redisson-client.zip

@geoand
Copy link
Contributor

geoand commented Jun 2, 2021

You can use a conditional substitution, something like so:

@TargetClass(value=NetUtil.class, onlyIf=Quarkus1Condition.class)
final class NetUtilSubstitutions {

   ....


    static class Quarkus1Condition implements BooleanSupplier {

        @Override
        public boolean getAsBoolean() {
            return Quarkus.class.getPackage().getImplementationVersion().startsWith("1.");
        }
    }

}

the version check I am doing here is likely not bulletproof, but it should be good enough

@mrniko
Copy link
Author

mrniko commented Jun 4, 2021

Thanks for the tip!

@mrniko mrniko closed this as completed Jun 4, 2021
@geoand geoand added the triage/invalid This doesn't seem right label Jun 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/native-image kind/bug Something isn't working triage/invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants