This is an automated email from the ASF dual-hosted git repository.
chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fury.git
The following commit(s) were added to refs/heads/main by this push:
new 8c45d959 fix(java): Fix for maximum size of java arrays (#1843)
8c45d959 is described below
commit 8c45d959d1d11fca0b4534f8497c98cc1902fb7b
Author: Arthur Finkelstein <[email protected]>
AuthorDate: Fri Sep 13 10:54:53 2024 +0200
fix(java): Fix for maximum size of java arrays (#1843)
## What does this PR do?
Fixes the maximum size of Java arrays using Integer.MAX_VALUE when it
should be Integer.MAX_VALUE - 8.
See this
https://github.com/openjdk/jdk14u/blob/84917a040a81af2863fddc6eace3dda3e31bf4b5/src/java.base/share/classes/jdk/internal/util/ArraysSupport.java#L577
or https://www.baeldung.com/java-arrays-max-size
## Related issues
- #1842
## Does this PR introduce any user-facing change?
No
- [ ] Does this PR introduce any public API change? No
- [ ] Does this PR introduce any binary protocol compatibility change?
No
## 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.
-->
Co-authored-by: Arthur Finkelstein <[email protected]>
---
java/fury-core/src/main/java/org/apache/fury/memory/MemoryBuffer.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git
a/java/fury-core/src/main/java/org/apache/fury/memory/MemoryBuffer.java
b/java/fury-core/src/main/java/org/apache/fury/memory/MemoryBuffer.java
index de3c64e0..79d6f2b7 100644
--- a/java/fury-core/src/main/java/org/apache/fury/memory/MemoryBuffer.java
+++ b/java/fury-core/src/main/java/org/apache/fury/memory/MemoryBuffer.java
@@ -1230,7 +1230,7 @@ public final class MemoryBuffer {
int newSize =
length < BUFFER_GROW_STEP_THRESHOLD
? length << 2
- : (int) Math.min(length * 1.5d, Integer.MAX_VALUE);
+ : (int) Math.min(length * 1.5d, Integer.MAX_VALUE - 8);
byte[] data = new byte[newSize];
copyToUnsafe(0, data, Platform.BYTE_ARRAY_OFFSET, size());
initHeapBuffer(data, 0, data.length);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]