Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8201593

Print array length in ArrayIndexOutOfBoundsException.

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 11
    • Fix Version/s: 11
    • Component/s: hotspot
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b14

      Backports

        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.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  goetz Goetz Lindenmaier
                  Reporter:
                  goetz Goetz Lindenmaier
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  2 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: