Skip to content

Commit

Permalink
fix(java): Fix max Java array size for reader (#1844)
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
Same as #1843 but for the reader.

## 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

Not needed

Co-authored-by: Arthur Finkelstein <[email protected]>
  • Loading branch information
fink-arthur and Arthur Finkelstein authored Sep 14, 2024
1 parent 8c45d95 commit d2677c5
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private static byte[] growBuffer(int minFillSize, MemoryBuffer buffer) {
newSize =
targetSize < MemoryBuffer.BUFFER_GROW_STEP_THRESHOLD
? targetSize << 2
: (int) Math.min(targetSize * 1.5d, Integer.MAX_VALUE);
: (int) Math.min(targetSize * 1.5d, Integer.MAX_VALUE - 8);
byte[] newBuffer = new byte[newSize];
byte[] heapMemory = buffer.getHeapMemory();
System.arraycopy(heapMemory, 0, newBuffer, 0, buffer.size());
Expand Down

0 comments on commit d2677c5

Please sign in to comment.