RFR: 8259925: [Vector API] Unreasonable IndexOutOfBoundsException message when length < vlen

Paul Sandoz psandoz at openjdk.java.net
Tue Jan 19 21:43:51 UTC 2021


On Mon, 18 Jan 2021 13:32:24 GMT, Jie Fu <jiefu at openjdk.org> wrote:

> Hi all,
> 
> For this reproducer:
> 
> import jdk.incubator.vector.ByteVector;
> import jdk.incubator.vector.VectorSpecies;
> 
> public class Test {
>     static final VectorSpecies<Byte> SPECIES_128 = ByteVector.SPECIES_128;
>     static byte[] a = new byte[8];
>     static byte[] b = new byte[8];
> 
>     public static void main(String[] args) {
>         ByteVector av = ByteVector.fromArray(SPECIES_128, a, 0);
>         av.intoArray(b, 0);
>         System.out.println("b: " + b[0]);
>     }
> }
> 
> The following IndexOutOfBoundsException message (length -7) is unreasonable.
> 
> Exception in thread "main" java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length -7
> 
> It might be better to fix it like this.
> 
> Exception in thread "main" java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
> 
> Thanks.
> Best regards,
> Jie

That change may cause performance issues. I would recommend leaving as is for now even through the error message is not great. Bounds checking is quite sensitive and WIP. Notice that we also have an option to call `Objects.checkFromIndexSize` which expresses the intent more accurately, but that is currently less optimal (at least it was when i last checked since it is non an intrinsic).

-------------

PR: https://git.openjdk.java.net/jdk/pull/2127


More information about the core-libs-dev mailing list