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

Vladimir Kozlov vladimir.kozlov at oracle.com
Thu Apr 9 16:22:43 UTC 2015


Tobias,

I also asked to use Utils::getRandomInstance() to get reproducible results.

Thanks,
Vladimir


On 4/9/15 5:10 AM, Tobias Hartmann wrote:
> 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