- changed title to Java 8:java.lang.NoSuchMethodError: java.nio.ByteBuffer.limit(I)Ljava/nio/ByteBuffer
Java 8:java.lang.NoSuchMethodError: java.nio.ByteBuffer.limit(I)Ljava/nio/ByteBuffer
Hi IJabz,
Please cast java.nio.ByteBuffer instances where necessary to java.nio.Buffer to avoid NoSuchMethodError when running on Java 8.
The Java 11+ ByteBuffer classes introduces overloaded methods with covariant return types for the following methods used by the driver:
- position
- limit
- flip
- clear
Without casting, exceptions like this are thrown when executing on Java 8 and lower:
java.lang.NoSuchMethodError: java.nio.ByteBuffer.limit(I)Ljava/nio/ByteBuffer
This is because the generated byte code includes the static return type of the method, which is not found on Java 8 and lower because the overloaded methods with covariant return types don't exist.
Example:
buf.position(newPosition);
((Buffer) buf).position(newPosition);
Summary:
works without problems if all references are changed.
Best regards
Comments (2)
-
repo owner -
repo owner Please provide a pull request if you want fixed as this is of little interest to me since I only use with Java 11 onwards.
- Log in to comment