RFR(M): 8201593: Print array length in ArrayIndexOutOfBoundsException.

Lindenmaier, Goetz goetz.lindenmaier at sap.com
Thu Apr 19 12:24:55 UTC 2018


Hi,

New webrev:
http://cr.openjdk.java.net/~goetz/wr18/8201593-lenInAIOOB/02/

I admit my wording is not optimal.
It's because I extracted this change from a bigger one. Our message reads like this:
Object [] oa1 = new Object[10]
oa1[12]
"ArrayIndexOutOfBoundsException while trying to load from index 12 of an object array with length 10, loaded from local variable 'oa1'"
... which seems not optimal, either. But it mentions the type (object), the operation (load, store etc ...) and the variable name.
Naming the array is quite detailed if it is in a complex expression (like returned from a call).
I'll contribute more of this if appreciated, this is a first step.

Printing "index N is outside range [0, length-1]" is problematic
for length '0'. I followed the proposal by Roger:
"Index -1 out-of-bounds for length 10."

I removed the change to ArrayIndexOutOfBoundsException.java.

I extended the test to cover the exception thrown in arraycopy better
and added the elementary type to the message text.  This probably 
needs improvement in the text, too.  There are (currently) these cases:

bject[]  oa1 = new Object[10];
Object[]  oa2 = new Object[5];
System.arraycopy(oa1, -17, oa2, 0, 5);
"while trying to copy from index -17 of an object array with length 10");
System.arraycopy(oa1, 2, oa2, -18, 5);
"while trying to copy to index -18 of an object array with length 5");
System.arraycopy(oa1, 2, oa2, 0, -19);
"while trying to copy a negative range -19 from an object array with length 10 to an object array with length 5");
System.arraycopy(oa1, 8, oa2, 0, 5);
"while trying to copy from index 13 of an object array with length 10");
System.arraycopy(oa1, 1, oa2, 0, 7);
"while trying to copy to index 7 of an object array with length 5");
double[]  ta1 = new double[10];
double[]  ta2 = new double[5];
System.arraycopy(ta1, -17, ta2, 0, 5);
"while trying to copy from index -17 of a doubl array with length 10");
System.arraycopy(ta1, 2, ta2, -18, 5);
"while trying to copy to index -18 of a double array with length 5");
System.arraycopy(ta1, 2, ta2, 0, -19);
"while trying to copy a negative range -19 from a double array with length 10 to a double array with length 5");
System.arraycopy(ta1, 8, ta2, 0, 5);
"while trying to copy from index 13 of a double array with length 10");
System.arraycopy(ta1, 1, ta2, 0, 7);
"while trying to copy to index 7 of a double array with length 5");

Maybe it should say:
Arraycopy source index -1 out-of-bounds for double array of length 10. 
Arraycopy target index 10 out-of-bounds for object array of length 10.
Negative range -19 when copying from an object array of length 10 to an object array of length 5.

Best regards,
  Goetz.

> -----Original Message-----
> From: David Holmes [mailto:david.holmes at oracle.com]
> Sent: Mittwoch, 18. April 2018 10:55
> To: Lindenmaier, Goetz <goetz.lindenmaier at sap.com>; hotspot-runtime-
> dev at openjdk.java.net; hotspot-compiler-dev at openjdk.java.net; aarch64-
> port-dev at openjdk.java.net; aarch32-port-dev at openjdk.java.net; core-libs-
> dev Libs <core-libs-dev at openjdk.java.net>
> Subject: Re: RFR(M): 8201593: Print array length in
> ArrayIndexOutOfBoundsException.
> 
> Adding core-libs-dev as you're changing
> java.lang.ArrayIndexOutOfBoundsException.
> 
> I appreciate the intent here but I find the messages excessively
> verbose. The basic error is:
> 
> index N is outside range [0, length-1]
> 
> David
> 
> On 18/04/2018 6:09 PM, Lindenmaier, Goetz wrote:
> > Hi,
> >
> > I would like to print a more verbose text on ArrayIndexOutOfBounds
> exception
> > that not only mentions the index, but also the length of the array accessed.
> > See the bug for documentation of the change of the message.
> > http://cr.openjdk.java.net/~goetz/wr18/8201593-lenInAIOOB/01/
> >
> > @aarch/arm people:
> > I edited the aarch/arm files. Could you please verify this is correct?
> > I can not build on these platforms.
> >
> > The code on all the other platforms is tested with all the jtreg and jck tests
> etc.
> >
> > Best regards,
> >    Goetz.
> >
> >


More information about the hotspot-runtime-dev mailing list