RFR for bug JDK-8030690 TEST_BUG java/nio/Buffer/Chars.java fails intermittently
Alan Bateman
Alan.Bateman at oracle.com
Thu Dec 19 06:59:13 PST 2013
On 19/12/2013 08:01, Eric Wang wrote:
> Hi Everyone,
>
> I'm working on the bug https://bugs.openjdk.java.net/browse/JDK-8030690.
> The test failed due to there's a logic fault in randomizeRange(), if
> cb.capacity() returns 1 then mid = cb.capacity() >>> 1 which is 0. it
> causes Random.nextInt(0) throws the IllegalArgumentException.
>
> So the suggested fix is to update the randomizeRange() like below.
>
> static CharBuffer randomizeRange(CharBuffer cb) {
> int mid = cb.capacity() >>> 1;
> int start = RAND.nextInt(mid + 1); // from 0 to mid
> int end = mid + RAND.nextInt(cb.capacity() - mid + 1); // from
> mid to capacity.
> cb.position(start);
> cb.limit(end);
> return cb;
> }
>
> Please let me know if you have any comment. The webrev will be sent soon.
The change looks okay in that the method will handle the case that the
capacity is 1. So it a slice that has a capacity of 1?
-Alan.
More information about the nio-dev
mailing list