-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Building Pulsar (incl. docker images) from source with Java 9+ (Java 11, Java 15, etc.) causes silent NoSuchMethodErrors at runtime #8445
Comments
@eolivelli I noticed that you had done some changes to allow compiling with JDK 14+. Have you come across the ByteBuffer incompatibilities? |
This problem should not only exist in 2.6.2, but it should also be a master problem, @zymap helped to verify the logic with JDK 1.8, it seems that everything is OK. It looks like we need to support different JDK versions to build Apache Pulsar. |
@lhotari We should add maven.compiler.release=8 in our pom.xml, it must be done in a profile activated when you are on jdk9+, it is a quite easy fix. that's a very common problem: |
@eolivelli I think it would be valuable. It's easy to miss that you must compile Pulsar with Java 8 since the compilation passes without errors and even at runtime the errors are swallowed and not logged (at least in this particular case). Very hard to debug. |
I guess that if you build with JDK14+ and you run everything on JDK14+ you won't hit problems. In BK community we are switching to JDK11+ (but still next release will work on JDK8) |
There is a blog post with an easy solution: https://www.morling.dev/blog/bytebuffer-and-the-dreaded-nosuchmethoderror/ .
|
You have to add it in a profile, because if you add only this property the build will break on jdk8 because the 'release' option is not valid with jdk8 |
…+ for compiling Fixes apache#8445 - Sets release in maven-compiler-plugin configuration this results in passing "--release 8" flag to the javac compiler - ensures that correct methods are chosen in compilation. For example, without passing the flag, incorrect java.nio.ByteBuffer methods will be chosen in the case that compilation is performed on Java 9+ and runtime uses Java 8. This results in NoSuchMethodErrors at runtime.
Building Pulsar (incl. docker images) from source with Java 11 causes silent NoSuchMethodErrors at runtime
To Reproduce
Steps to reproduce the behavior:
Use Java 11.
Then, compile v2.6.2-candidate-1 docker images locally:
Start pulsar in docker
Compile & run this Pulsar code with required libraries:
The producer never gets created and it times out.
What happens on a server is a
java.lang.NoSuchMethodError: java.nio.ByteBuffer.rewind()Ljava/nio/ByteBuffer;
This happens at
pulsar/pulsar-common/src/main/java/org/apache/pulsar/common/schema/LongSchemaVersion.java
Line 44 in 097108a
This exception never gets printed to the log, this stacktrace was captured using the debugger.
Expected behavior
Compiling with an unsupported Java version should result in an error and the NoSuchMethodError that happens in Pulsar shouldn't get "swallowed".
It should be possible to compile the code with Java 9+ without running into issues when running with Java 8.
There's an explanation of the issue with ByteBuffer at jetty/jetty.project#3244 . A solution is also described:
The text was updated successfully, but these errors were encountered: