-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
NoSuchMethodError: java.nio.ByteBuffer.limit(I)Ljava/nio/ByteBuffer #3244
Comments
To be clear this is because Java 9 introduced a Covariant return type that when compiled with Java 9+ includes the return type in the (jetty) bytecode, rendering the bytecode incompatible with Java 8. |
@joakime correct. The call I'm still astonished that JDK 9's |
REALLY??? ugh! However, we don't want to "fix" this in jetty-10 as that is never intended to be run on java8, so do we just need to fix this in jetty-9? |
@gregw, correct we only need it in 9.4.x. |
I also run into this problem, any update upon this ? |
@DreamWuGit to work around, in your project, compile with JDK8, run with any JDK. |
@joakime but the problem is that Maven Central artifacts that we produce are compiled with JDK 9+. |
Sorry to butt in here, but I see this and several other projects adding unnecessary casts for this issue. I have never seen javac produce the wrong bytecodes when given the proper Now if |
@stuart-marks I just double checked this and you are right, We do have a profile that is automatically enabled when compiling with JDK > 8 (https://github.com/eclipse/jetty.project/blob/jetty-9.4.18.v20190429/pom.xml#L1843) that enforces |
Thank you, @sbordet. I'm new to Java and your comment helped me fix the issue quickly! |
* Update JNA to resolve framework loading issue on Big Sur java-native-access/jna#1215 * Remove workaround initializing JNA early java-native-access/jna#652 This issue was resolved and property SIZE does not exist with JNA version 5.6.0. * Update NuProcess to 2.0.1 for compatibility with JNA * Build NuProcess with openjdk version "1.8.0_275" jetty/jetty.project#3244 * Cherry pick a2912b9 a2912b9
When compiled with Java 9+, even when the compilation target is Java 8 ByteBuffer.position calls result in a `java.lang.NoSuchMethodError: java.nio.ByteBuffer.position(I)Ljava/nio/ByteBuffer;` error when running in a Java 8 JVM (see [this issue](jetty/jetty.project#3244)). Casting to java.nio.Buffer before calling position avoids the error.
* Update JNA to resolve framework loading issue on Big Sur java-native-access/jna#1215 * Remove workaround initializing JNA early java-native-access/jna#652 This issue was resolved and property SIZE does not exist with JNA version 5.6.0. * Update NuProcess to 2.0.1 for compatibility with JNA * Build NuProcess with openjdk version "1.8.0_275" jetty/jetty.project#3244 * Cherry pick a2912b9 facebook@a2912b9
When we build with Java 9+ and target for Java 8, we get an incompatible bytecode around these method for `ByteBuffer`: ``` position(int) limit(int) mark() reset() clear() flip() rewind() ``` The recommendation is to cast to `Buffer` when we call these methods * Fix all the production code using `ByteBuffer` for recommended cast to `Buffer` Related to https://build.spring.io/browse/INTEXT-AWS-306 See more info in this Jetty issue: jetty/jetty.project#3244
When we build with Java 9+ and target for Java 8, we get an incompatible bytecode around these method for `ByteBuffer`: ``` position(int) limit(int) mark() reset() clear() flip() rewind() ``` The recommendation is to cast to `Buffer` when we call these methods * Fix all the production code using `ByteBuffer` for recommended cast to `Buffer` Related to https://build.spring.io/browse/INTEXT-AWS-306 See more info in this Jetty issue: jetty/jetty.project#3244
* Update JNA to resolve framework loading issue on Big Sur java-native-access/jna#1215 * Remove workaround initializing JNA early java-native-access/jna#652 This issue was resolved and property SIZE does not exist with JNA version 5.6.0. * Update NuProcess to 2.0.1 for compatibility with JNA * Build NuProcess with openjdk version "1.8.0_275" jetty/jetty.project#3244 * Cherry pick a2912b9 facebook@a2912b9
* Update JNA to resolve framework loading issue on Big Sur java-native-access/jna#1215 * Remove workaround initializing JNA early java-native-access/jna#652 This issue was resolved and property SIZE does not exist with JNA version 5.6.0. * Update NuProcess to 2.0.1 for compatibility with JNA * Build NuProcess with openjdk version "1.8.0_275" jetty/jetty.project#3244 * Cherry pick a2912b9 facebook@a2912b9
* Update JNA to resolve framework loading issue on Big Sur java-native-access/jna#1215 * Remove workaround initializing JNA early java-native-access/jna#652 This issue was resolved and property SIZE does not exist with JNA version 5.6.0. * Update NuProcess to 2.0.1 for compatibility with JNA * Build NuProcess with openjdk version "1.8.0_275" jetty/jetty.project#3244 * Cherry pick a2912b9 facebook@a2912b9
* make spark ddp works correctly when compiling by jdk9+ and running on jdk8 * refer to: jetty/jetty.project#3244 * partially backport StarRocks#33738 * upgrade maven-compiler-plugin to 3.13.0 so it can automatically ignore the release configuration when build with jdk8 Signed-off-by: Kevin Xiaohua Cai <[email protected]>
Like many other projects (Tomcat, MongoDB, etc.) compiling with JDK 9+ with release 8 produces incorrect bytecode for these ByteBuffer methods:
position(int)
limit(int)
mark()
reset()
clear()
flip()
rewind()
Running a Jetty compiled with JDK 9+ with release 8 in a JDK 8 JVM will produce a
NoSuchMethodError
.The solution is to cast the
ByteBuffer
toBuffer
when calling those methods:The text was updated successfully, but these errors were encountered: