Howdy,
When I am trying to generate a native image on a project with Netty dependency I get the following error:
Error: Classes that should be initialized at run time got initialized during image building:
io.netty.channel.DefaultFileRegion the class was requested to be initialized at build time (subtype of io.netty.util.AbstractReferenceCounted and from the command line). io.netty.channel.DefaultFileRegion has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try avoiding to initialize the class that caused initialization of io.netty.channel.DefaultFileRegion
io.netty.util.AbstractReferenceCounted the class was requested to be initialized at build time (from the command line). io.netty.util.AbstractReferenceCounted has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try avoiding to initialize the class that caused initialization of io.netty.util.AbstractReferenceCounted
com.oracle.svm.core.util.UserError$UserException: Classes that should be initialized at run time got initialized during image building:
io.netty.channel.DefaultFileRegion the class was requested to be initialized at build time (subtype of io.netty.util.AbstractReferenceCounted and from the command line). io.netty.channel.DefaultFileRegion has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try avoiding to initialize the class that caused initialization of io.netty.channel.DefaultFileRegion
io.netty.util.AbstractReferenceCounted the class was requested to be initialized at build time (from the command line). io.netty.util.AbstractReferenceCounted has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try avoiding to initialize the class that caused initialization of io.netty.util.AbstractReferenceCounted
at com.oracle.svm.core.util.UserError.abort(UserError.java:65)
at com.oracle.svm.hosted.classinitialization.ConfigurableClassInitialization.checkDelayedInitialization(ConfigurableClassInitialization.java:510)
at com.oracle.svm.hosted.classinitialization.ClassInitializationFeature.duringAnalysis(ClassInitializationFeature.java:187)
at com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$8(NativeImageGenerator.java:710)
at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:63)
at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:710)
at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:530)
at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:445)
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
com.oracle.svm.driver.NativeImage$NativeImageError: Image build request failed with exit status 1
at com.oracle.svm.driver.NativeImage.showError(NativeImage.java:1482)
at com.oracle.svm.driver.NativeImage.build(NativeImage.java:1260)
at com.oracle.svm.driver.NativeImage.performBuild(NativeImage.java:1222)
at com.oracle.svm.driver.NativeImage.main(NativeImage.java:1181)
Are there any recommendations on how to troubleshoot this and find the offending class?
Additional info
HI @tovbinm I was able to verify creating and running an application using netty 4.1.44Final without a problem. I used the latest version of micronaut and overrode the netty dependency version to point to the one you are having problems with. That worked fine. One thing I can think of is that somewhere in your code you might be initializing a class that has been marked as runtime by netty.
The micronaut project has a number of property files that are worth reviewing when using netty with native-image, for example https://github.com/micronaut-projects/micronaut-core/blob/master/http-netty/src/main/resources/META-INF/native-image/io.micronaut/netty/native-image.properties
@eginez thank you for looking into this. I will try debugging it further.
The most confusing part for me is that the error does not provide any additional information which part of my code (or code of one of my dependencies) initializes the classes DefaultFileRegion and AbstractReferenceCounted. Is there a way you would suggest to troubleshoot this?
This exact issue still occurs in the below version when running native-image.
openjdk 11.0.6 2020-01-14
OpenJDK Runtime Environment GraalVM CE 20.0.0 (build 11.0.6+9-jvmci-20.0-b02)
OpenJDK 64-Bit Server VM GraalVM CE 20.0.0 (build 11.0.6+9-jvmci-20.0-b02, mixed mode, sharing)
Both of the Below Commands Have Been Tried To Build a Native Image of Waterfall For Minecraft
native-image -jar Waterfall.jar -H:+TraceClassInitialization --initialize-at-build-time=org.apache.logging.log4j,org.apache.logging.slf4j,org.slf4j,org.jline,net.minecrell,com.lmax.disruptor
native-image -jar Waterfall.jar -H:+TraceClassInitialization --initialize-at-build-time=org.apache.logging.log4j,org.apache.logging.slf4j,org.slf4j,org.jline,net.minecrell,com.lmax.disruptor --initialize-at-run-time=io.netty.util.AbstractReferenceCounted
Running just native-image -jar Waterfall.jar still causes the netty initialization issue.
The error message for the netty issue is:
Error: Classes that should be initialized at run time got initialized during image building:
io.netty.util.AbstractReferenceCounted the class was requested to be initialized at build time (from the command line). io.netty.util.AbstractReferenceCounted has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try avoiding to initialize the class that caused initialization of io.netty.util.AbstractReferenceCounted
Using native-image -jar Waterfall.jar -H:+TraceClassInitialization -H:+ReportExceptionStackTraces --initialize-at-build-time=org.apache.logging.log4j,org.apache.logging.slf4j,org.slf4j,org.jline,net.minecrell,com.lmax.disruptor --initialize-at-run-time=io.netty.util.AbstractReferenceCounted
I get the errors
Error: Classes that should be initialized at run time got initialized during image building:
io.netty.util.AbstractReferenceCounted the class was requested to be initialized at build time (from the command line). io.netty.util.AbstractReferenceCounted has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try avoiding to initialize the class that caused initialization of io.netty.util.AbstractReferenceCounted
com.oracle.svm.core.util.UserError$UserException: Classes that should be initialized at run time got initialized during image building:
io.netty.util.AbstractReferenceCounted the class was requested to be initialized at build time (from the command line). io.netty.util.AbstractReferenceCounted has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try avoiding to initialize the class that caused initialization of io.netty.util.AbstractReferenceCounted
The full error message is located at this gist.
Edit: I posted this as I have found no way to debug an image build given the options I have tried. I am not sure how to solve the issue and not handling the tracing of the initialization well is not what I believe to be intended design.
I experienced the same exception when I use EpollEventLoopGroup in my method (not in the static initialization block).
I tried to use the "Tracing Agent“ feature (https://www.graalvm.org/docs/reference-manual/native-image/). It helps in my case, though I see another problem after it (not sure whether it is related).
To someone who has this issue too, please try to use "Tracing Agent“. It might help with your case.
edit: Seems the "Tracing Agent“ would generate incorrect files and cause the another problem before the native-images see this problem. So my idea would not work here.
I'm seeing the same thing with a basic hello world netty app using epoll native transport.
Most helpful comment
This exact issue still occurs in the below version when running native-image.
Both of the Below Commands Have Been Tried To Build a Native Image of Waterfall For Minecraft
Running just
native-image -jar Waterfall.jarstill causes the netty initialization issue.The error message for the netty issue is:
Using
native-image -jar Waterfall.jar -H:+TraceClassInitialization -H:+ReportExceptionStackTraces --initialize-at-build-time=org.apache.logging.log4j,org.apache.logging.slf4j,org.slf4j,org.jline,net.minecrell,com.lmax.disruptor --initialize-at-run-time=io.netty.util.AbstractReferenceCountedI get the errors
The full error message is located at this gist.
Edit: I posted this as I have found no way to debug an image build given the options I have tried. I am not sure how to solve the issue and not handling the tracing of the initialization well is not what I believe to be intended design.