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

Print array length in ArrayIndexOutOfBoundsException.

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 11
    • 11
    • hotspot
    • None
    • b14

        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.

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

                Created:
                Updated:
                Resolved: