Skip to content

Commit

Permalink
[#6712] Fix issue with jdk incompatibility in java RPC client
Browse files Browse the repository at this point in the history
Summary:
See #6712 for
more details. The signature of ByteBuffer::flip changed between JDK 8 and 9. So when
the client is compiled using Java >8 and run with Java 8, it fails to
"link" the flip method and results in a NoSuchMethod error.

The fix converts the code to always use Buffer.flip instead of the
derived method. This should be not result in a loss of functionality
because the implementation of the flip in the derived class seems to be
the same as the parent class but just returns a different type. See
http://hg.openjdk.java.net/jdk9/sandbox/jdk/file/7d9bd66d2bb9/src/java.base/share/classes/java/nio/X-Buffer.java.template#l1148

The issue highlights another problem in the Java RPC client - it seems
like the error NoSuchMethodException is just swallowed somewhere along
the path. The 'sync' YBClient calls the AsyncYBClient but it might not
provide an 'errback' for the error that results from this call.

Test Plan:
Compile with Java 11, run with Java 8, verify the error is
fixed.

Reviewers: arnav, streddy, daniel

Reviewed By: streddy, daniel

Subscribers: streddy, yugaware

Differential Revision: https://phabricator.dev.yugabyte.com/D10183
  • Loading branch information
iSignal committed Mar 10, 2021
1 parent 4385ad3 commit 49ae720
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions java/yb-client/src/main/java/org/yb/util/Slices.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.google.common.base.Preconditions;
import org.yb.annotations.InterfaceAudience;

import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.CharBuffer;
Expand Down Expand Up @@ -149,7 +150,8 @@ public static ByteBuffer encodeString(CharBuffer src, Charset charset)
catch (CharacterCodingException x) {
throw new IllegalStateException(x);
}
dst.flip();
// See https://github.com/yugabyte/yugabyte-db/issues/6712
((Buffer)dst).flip();
return dst;
}

Expand All @@ -171,7 +173,8 @@ public static String decodeString(ByteBuffer src, Charset charset)
catch (CharacterCodingException x) {
throw new IllegalStateException(x);
}
return dst.flip().toString();
// See https://github.com/yugabyte/yugabyte-db/issues/6712
return ((Buffer)dst).flip().toString();
}

/**
Expand Down

0 comments on commit 49ae720

Please sign in to comment.