Skip to content

Commit e33a1f7

Browse files
authored
fix(java): Fix error with MemoryBuffer::readBytesAsInt64 when not in LITTLE_ENDIAN mode #2068 (#2069)
## What does this PR do? Fix the issue with `MemoryBuffer::readBytesAsInt64` when the system is not in LITTLE_ENDIAN mode. ## Related issues - Fix #2068 ## Does this PR introduce any user-facing change? <!-- If any user-facing interface changes, please [open an issue](https://github.com/apache/fury/issues/new/choose) describing the need to do so and update the document if necessary. --> - [ ] Does this PR introduce any public API change? - [ ] Does this PR introduce any binary protocol compatibility change? ## Benchmark <!-- When the PR has an impact on performance (if you don't know whether the PR will have an impact on performance, you can submit the PR first, and if it will have impact on performance, the code reviewer will explain it), be sure to attach a benchmark data here. -->
1 parent bda04fe commit e33a1f7

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

java/fury-core/src/main/java/org/apache/fury/memory/MemoryBuffer.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -2198,10 +2198,9 @@ public long readBytesAsInt64(int len) {
21982198
int remaining = size - readerIdx;
21992199
if (remaining >= 8) {
22002200
readerIndex = readerIdx + len;
2201-
long v =
2202-
UNSAFE.getLong(heapMemory, address + readerIdx)
2203-
& (0xffffffffffffffffL >>> ((8 - len) * 8));
2204-
return LITTLE_ENDIAN ? v : Long.reverseBytes(v);
2201+
long v = UNSAFE.getLong(heapMemory, address + readerIdx);
2202+
v = (LITTLE_ENDIAN ? v : Long.reverseBytes(v)) & (0xffffffffffffffffL >>> ((8 - len) * 8));
2203+
return v;
22052204
}
22062205
return slowReadBytesAsInt64(remaining, len);
22072206
}

0 commit comments

Comments
 (0)