Skip to content

Commit

Permalink
fix(java): Fix for maximum size of java arrays (#1843)
Browse files Browse the repository at this point in the history
## 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 <arthur.finkelstein@instant-system.com>
  • Loading branch information
fink-arthur and Arthur Finkelstein authored Sep 13, 2024
1 parent 7de0cdd commit 8c45d95
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ private void growBuffer(int length) {
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);
Expand Down

0 comments on commit 8c45d95

Please sign in to comment.