Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java] Maximum size of Java arrays is not correct #1842

Closed
2 tasks done
fink-arthur opened this issue Sep 13, 2024 · 0 comments
Closed
2 tasks done

[Java] Maximum size of Java arrays is not correct #1842

fink-arthur opened this issue Sep 13, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@fink-arthur
Copy link
Contributor

Search before asking

  • I had searched in the issues and found no similar issues.

Version

8.1.0

Component(s)

Java

Minimal reproduce step

MemoryBuffer memoryBuffer = MemoryBuffer.newHeapBuffer(10);
memoryBuffer.grow(Integer.MAX_VALUE);

What did you expect to see?

A MemoryBuffer of the maximum size

What did you see instead?

java.lang.OutOfMemoryError: Requested array size exceeds VM limit

Anything Else?

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR!
@fink-arthur fink-arthur added the bug Something isn't working label Sep 13, 2024
@fink-arthur fink-arthur changed the title Maximum size of Java arrays is not correct [Java] Maximum size of Java arrays is not correct Sep 13, 2024
chaokunyang pushed a commit that referenced this issue Sep 13, 2024
## 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]>
chaokunyang pushed a commit that referenced this issue Sep 14, 2024
## 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant