JDK-8201593 : Print array length in ArrayIndexOutOfBoundsException.
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 11
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2018-04-16
  • Updated: 2021-09-24
  • Resolved: 2018-05-14
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 11
11 b14Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
To analyse ArrayIndexOutOfBounds exceptions it's useful to know the length of the array accessed.

Example for load from / store to array with illegal index:
int[] a = new int[3];
a[7];
Message before: 
7
Message now:
Index 7 out of bounds for length 3

arraycopy() also reports ArrayIndexOutOfBoundsExceptions.
Before, it did not report any context for the exception. Now it says:

arraycopy: source index -17 out of bounds for boolean[10]
arraycopy: destination index -18 out of bounds for byte[5]
arraycopy: last source index 13 out of bounds for char[10]
arraycopy: last destination index 7 out of bounds for object array[5]
arraycopy: length -19 is negative

It was agreed to spell "out of bounds" with hyphens if used as an adjective, else without, which is the case here.  See also 8202745.


Comments
URL: http://hg.openjdk.java.net/jdk/jdk/rev/2f79462aab9b User: goetz Date: 2018-05-14 08:49:59 +0000
14-05-2018

The message " trying to access index -5 of an array with length 3 " makes no sense. You're trying to access Element -5, not its index, so the message should be "trying to access element -5 of an array with length 3" or (better IMO) "index -5 out of range in array[3]".
18-04-2018