JDK-8247373 : ArraysSupport.newLength doc, test, and exception message
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2020-06-10
  • Updated: 2025-01-16
  • Resolved: 2021-03-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 17
17 b13Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Sub Tasks
JDK-8299237 :  
Description
ArraysSupport.newLength is an internal method in jdk.internal.util that does safe array length computations.

1) It throws OutOfMemoryError in certain cases. The message should include the details of the request (current length + required minimum growth) that could not be fulfilled.

2) The doc comment is fairly verbose, yet it doesn't explain the method very well nor why it's useful. See the writeup here:

http://mail.openjdk.java.net/pipermail/core-libs-dev/2020-June/066928.html

This is part of a larger discussion on this thread:

http://mail.openjdk.java.net/pipermail/core-libs-dev/2020-May/066844.html
http://mail.openjdk.java.net/pipermail/core-libs-dev/2020-June/066865.html

3) There is no unit test for this method. Given its intricacy, it should have one.
Comments
[~coffeys] I think you're right! Gaaah, I hate it when this happens! I'll add a subtask.
21-12-2022

I don't think the new test added for this fix belongs to any test group: test/jdk/jdk/internal/util/ArraysSupport/NewLength.java Perhaps TEST.groups can be fixed up as a subtask.
21-12-2022

Changeset: f18c0192 Author: Stuart Marks <smarks@openjdk.org> Date: 2021-03-02 18:08:26 +0000 URL: https://git.openjdk.java.net/jdk/commit/f18c0192
02-03-2021

A follow-on mini-project would be to go around the system and update various locations to use ArraysSupport.newLength instead of having copies of slight variations of this code sprinkled around the JDK. Lists of potential candidates can be found in bugs JDK-8246725 and JDK-8230744.
13-06-2020

See also related core-libs-dev thread on JDK-8230744, "Several classes throw OutOfMemoryError without message": http://mail.openjdk.java.net/pipermail/core-libs-dev/2020-June/066874.html
13-06-2020

Thanks. I'm a special fan of testing this because it's surprisingly easy to get wrong, is only likely to fail in production under stress, and then is unlikely to get properly diagnosed.
10-06-2020