Skip to content

Commit 1f5c92d

Browse files
Oleg ObolenskiyTotktonada
Oleg Obolenskiy
authored andcommitted
Fix NoSuchMethodError when Buffer.clear() is called
Tarantool client uses java.nio.ByteBuffer to represent a payload to be sent through the network. JDK 9 introduces a number of new methods that override java.nio.Buffer methods in order to return ByteBuffer instead of Buffer. Because of overriding, those methods are available in JRE 8 or below but cannot be invoked if the connector is built using JDK 9 or above using new signatures for methods overridden. To be compatible with JREs before 9, it possible to cast ByteBuffer to Buffer class explicitly. As a result, a method will be called which is available in older versions but it breaks conciseness of the code. Closes: #215
1 parent 66a4fbd commit 1f5c92d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/main/java/org/tarantool/protocol/ProtoUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.net.Socket;
1616
import java.net.SocketAddress;
1717
import java.net.SocketException;
18+
import java.nio.Buffer;
1819
import java.nio.ByteBuffer;
1920
import java.nio.channels.NonReadableChannelException;
2021
import java.nio.channels.ReadableByteChannel;
@@ -180,7 +181,7 @@ public static TarantoolGreeting connect(SocketChannel channel,
180181
assertCorrectWelcome(firstLine, channel.getRemoteAddress());
181182
final String serverVersion = firstLine.substring(WELCOME.length());
182183

183-
welcomeBytes.clear();
184+
((Buffer)welcomeBytes).clear();
184185
channel.read(welcomeBytes);
185186
String salt = new String(welcomeBytes.array());
186187

0 commit comments

Comments
 (0)