[9] RFR(XS): 8076625: IndexOutOfBoundsException in HeapByteBufferTest.java

Tobias Hartmann tobias.hartmann at oracle.com
Thu Apr 9 12:10:22 UTC 2015


Hi,

please review the following patch.

https://bugs.openjdk.java.net/browse/JDK-8076625
http://cr.openjdk.java.net/~thartmann/8076625/webrev.00/

Problem:
A random offset to access in a byte array is computed by 

  int randomOffset(SplittableRandom r, MyByteBuffer buf, int size) {
    return abs(r.nextInt()) % (buf.capacity() - size);
  }

The call to r.nextInt() may return Integer.MIN_VALUE (-2147483648) and the corresponding absolute value (+2147483648) does not fit into an int and will overflow back to -2147483648. As a result the returned offset is negative.

Solution:
Use nextInt(int n) to set the limit of the random value.

Testing:
Failing testcase and JPRT.

Thanks,
Tobias


More information about the hotspot-compiler-dev mailing list