Skip to content

Commit 31feb7e

Browse files
committed
Call position method of java.nio.Buffer instead of java.nio.ByteBuffer to be compatible with jdk8
1 parent 857c832 commit 31feb7e

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/buffer/ChannelBuffersTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.dubbo.remoting.buffer;
1818

19+
import java.nio.Buffer;
1920
import java.nio.ByteBuffer;
2021

2122
import org.junit.jupiter.api.Assertions;
@@ -75,7 +76,8 @@ void testWrappedBuffer() {
7576
channelBuffer = ChannelBuffers.wrappedBuffer(byteBuffer);
7677
Assertions.assertTrue(channelBuffer instanceof ByteBufferBackedChannelBuffer);
7778

78-
byteBuffer.position(byteBuffer.limit());
79+
// be compatible with jdk8 by casting byteBuffer's type to its parent class - `java.nio.Buffer`.
80+
((Buffer) byteBuffer).position(byteBuffer.limit());
7981
channelBuffer = ChannelBuffers.wrappedBuffer(byteBuffer);
8082
Assertions.assertEquals(channelBuffer, EMPTY_BUFFER);
8183
}

dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleCustomerProtocolWrapper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.apache.dubbo.common.utils.Assert;
2020
import org.apache.dubbo.common.utils.CollectionUtils;
2121

22+
import java.nio.Buffer;
2223
import java.nio.ByteBuffer;
2324
import java.nio.charset.StandardCharsets;
2425
import java.util.ArrayList;
@@ -67,7 +68,8 @@ public static int readRawVarint32(ByteBuffer byteBuffer) {
6768
val = val << 7;
6869
val = val | (byteBuffer.get(index) & 0x7F);
6970
}
70-
byteBuffer.position(currentPosition + varIntLength);
71+
// be compatible with jdk8 by casting byteBuffer's type to its parent class - `java.nio.Buffer`.
72+
((Buffer) byteBuffer).position(currentPosition + varIntLength);
7173
return val;
7274
}
7375

0 commit comments

Comments
 (0)