Skip to content

Commit c46a8db

Browse files
authored
Fix NoSuchMethodError on Java 8 for java.nio.ByteBuffer (#1782)
Signed-off-by: yhmo <yihua.mo@zilliz.com>
1 parent 4a7d705 commit c46a8db

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

sdk-core/src/main/java/io/milvus/common/utils/Float16Utils.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.milvus.common.utils;
22

3+
import java.nio.Buffer;
34
import java.nio.ByteBuffer;
45
import java.nio.ByteOrder;
56
import java.nio.ShortBuffer;
@@ -161,7 +162,7 @@ public static ByteBuffer f32VectorToBf16Buffer(List<Float> vector) {
161162
* @return List of Float a float32 vector
162163
*/
163164
public static List<Float> fp16BufferToVector(ByteBuffer buf) {
164-
buf.rewind(); // reset the read position
165+
((Buffer) buf).rewind(); // reset the read position
165166
List<Float> vector = new ArrayList<>();
166167
ShortBuffer sbuf = buf.asShortBuffer();
167168
for (int i = 0; i < sbuf.limit(); i++) {
@@ -198,7 +199,7 @@ public static ByteBuffer f32VectorToFp16Buffer(List<Float> vector) {
198199
* @return List of Float the vector is converted to float32 values
199200
*/
200201
public static List<Float> bf16BufferToVector(ByteBuffer buf) {
201-
buf.rewind(); // reset the read position
202+
((Buffer) buf).rewind(); // reset the read position
202203
List<Float> vector = new ArrayList<>();
203204
ShortBuffer sbuf = buf.asShortBuffer();
204205
for (int i = 0; i < sbuf.limit(); i++) {
@@ -234,7 +235,7 @@ public static ByteBuffer f16VectorToBuffer(List<Short> vector) {
234235
* @return List of Short the vector is converted to a list of Short, each Short value is a float16 value
235236
*/
236237
public static List<Short> bufferToF16Vector(ByteBuffer buf) {
237-
buf.rewind(); // reset the read position
238+
((Buffer) buf).rewind(); // reset the read position
238239
List<Short> vector = new ArrayList<>();
239240
ShortBuffer sbuf = buf.asShortBuffer();
240241
for (int i = 0; i < sbuf.limit(); i++) {

sdk-core/src/main/java/io/milvus/param/ParamUtils.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.apache.commons.collections4.MapUtils;
3838
import org.apache.commons.lang3.StringUtils;
3939

40+
import java.nio.Buffer;
4041
import java.nio.ByteBuffer;
4142
import java.nio.ByteOrder;
4243
import java.util.*;
@@ -1329,11 +1330,11 @@ public static SortedMap<Long, Float> decodeSparseFloatVector(ByteBuffer buf) {
13291330
pBuf.put(aa[k]); // fill the first 4 bytes with the unit bytes
13301331
}
13311332
pBuf.putInt(0); // fill the last 4 bytes to zero
1332-
pBuf.rewind(); // reset position to head
1333+
((Buffer) pBuf).rewind(); // reset position to head
13331334
long k = pBuf.getLong(); // this is the long value converted from the uint
13341335

13351336
// here we get the float value as normal
1336-
buf.position(offset + 4); // position offsets 4 bytes since they were converted to long
1337+
((Buffer) buf).position(offset + 4); // position offsets 4 bytes since they were converted to long
13371338
float v = buf.getFloat(); // this is the float value
13381339
sparse.put(k, v);
13391340
}

0 commit comments

Comments
 (0)