-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
ClassNotFoundException: com.jcraft.jzlib.Deflater when generating native image #494
Comments
AFAIK JSch has implicit dependency on JZlib, but since Java's class loading is lazy you won't get ClassNotFoundException on JVM if you don't trigger JZlib usage. Native-image tool in Graal doesn't load classes lazily, but eagerly and that's why it fails, I guess. Some stubbing is probably needed. |
@tarsa is right, however, when using |
I found where it came from: jzlib is an optional dependency of netty-codec, but not on my classpath. So it's surprising that other people seem to have been successful with native images and netty. That's probably enough to be able to reproduce the issue? |
Thank you for investigating further. I was able to reproduce this with a minimal test case, however it's a somewhat complicated corner case, a proper solution for it will take some work. I guess your code reaches into some parts of netty that makes jzlib reachable. You probably use more of netty than we have tried before. |
Adding jzlib to the classpath fixes it. But that's a workaround really. |
@dsyer I am using this substitution to resolve this
Looking at original method here I think SVM thinks there are paths that will call this method with |
I believe that is correct. The app runs fine for me with no jzlib anyway. |
@tsachev your substitution looks correct. You might want to add a runtime check for the value of |
Problem exists in release 1.0 RC5 too. |
I guess we need to see if the condition can be updated on Netty side to be more strict or if Graal flow analysis could be improved to avoid this false positive. Any thoughts @normanmaurer? |
I think the problem here is that In theory, if Graal does some "tree shaking" unused code elimination before attempting a compile, the JZlib classes should get shaken out, if they are not referenced whatsoever in the closure of the application entry point. How doable that is in practice is an open question - flow analysis has its limits. The only Netty-side fix I can imagine would be to move the JZlib-based encoders and decoders to a separate project. Workaround is simple: Include JZlib on the classpath. Not nice, since in most cases it will not be used, but does solve the problem. |
@timboudreau our analysis already shakes off a lot of unused code, however, as you point out, flow analysis has its limits and it sees the code that uses JZlib as reachable. |
This change set ddbf8fe should allow |
Thanks, I can confirm that Spring WebFlux + Reactor Netty compiles and run correctly with @normanmaurer Even if @cstancu workaround makes it less critical, if you want to improve Netty compatibilty with Graal, GraalVM now offers an official way to detect its presence via the |
@sdeleuze yes please and link this issue. |
@cstancu is it possible that some small change in the way Netty uses the jzlib code would allow that code to be shaken out at image build time? Do we know the path that makes it determined to be reachable? |
The decision over which zlib encoder/decoder to use seems to be made in
With sufficient inlining by the end of the compilation we should be able to constant fold With I think this approach would fix this Netty use case. I cannot think of a small change in Netty that would currently work. |
I will close this issue since the original reported error is fixed with the current approach, i.e., |
I'm not sure when this was "fixed". I'm using rc5 and still having the same problem. If you mark an issue "fixed" could you please consider adding a milestone or label to it? |
This fix will be available in rc6. We usually close issues once the fix is merged into master. We will look into tagging issues with the release version. |
This is happening again using rc9. Steps to reproduce it:
|
Running into the same issue with rc9 even with --report-unsupported-elements-at-runtime |
JZlib is not used or required by my app. Looks like maybe something Graal is trying to accesss?
The text was updated successfully, but these errors were encountered: