[vector] Error message in the fromArray length check is misleading

Adam Pocock adam.pocock at oracle.com
Wed Jan 30 16:31:39 UTC 2019


I'm vectorising a simple application which operates on fixed length 
arrays, and due to a mistake in the way I was iterating the arrays I 
kept triggering the IndexOutOfBoundsException. The message for this 
exception is pretty misleading, as all my vectors are of length 50, but 
the error message says:

java.lang.IndexOutOfBoundsException: Index 48 out of bounds for length 47
     at 
java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
     at 
java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
     at 
java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
     at java.base/java.util.Objects.checkIndex(Objects.java:372)
     at 
jdk.incubator.vector/jdk.incubator.vector.VectorIntrinsics.checkIndex(VectorIntrinsics.java:405)
     at 
jdk.incubator.vector/jdk.incubator.vector.Double256Vector$Double256Species.fromArray(Double256Vector.java:1433)

I realise my code is blowing past the end of the array & triggering the 
exception (which is good, as my code was wrong), but I feel like the 
message should say "Index 50 is out of bounds for length 50", or 
something similar, rather than saying my array is of a different length 
to what's actually allocated.

Maybe in VectorIntrinsics line 405
     case 2: return Objects.checkIndex(ix, length - (vlen - 1));
it could be modified to check if ix + vlen is below length, rather than 
if ix is below length - (vlen -1)?

Thanks,

Adam

-- 
Adam Pocock
Principal Member of Technical Staff
Machine Learning Research Group
Oracle Labs, Burlington, MA



More information about the panama-dev mailing list