RFR for bug JDK-8030690 TEST_BUG java/nio/Buffer/Chars.java fails intermittently

Eric Wang yiming.wang at oracle.com
Thu Dec 19 23:17:33 PST 2013


On 2013/12/19 22:59, Alan Bateman wrote:
> 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.
Hi Alan,

Please review the webrev 
http://cr.openjdk.java.net/~ewang/JDK-8030690/webrev.00/ 
<http://cr.openjdk.java.net/%7Eewang/JDK-8030690/webrev.00/>, if it 
looks OK, could you help to be the sponsor to check in?
Here is explanation why a slice has 1 capacity:

In the addCase(...) method, it calls randomize(sb) which calls 
randomizeRange(sb), it may set a CharBuffer position equals to limit - 
1, so the next call of sb.slice() returns a CharBuffer which capacity is 1.

Thanks,
Eric

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20131220/423c3939/attachment.html 


More information about the nio-dev mailing list