8200449: ReadAllReadNTransferTo fails occasionally

Don't pass a non-positive parameter to Random.nextInt(int).

Reviewed-by: chegar
This commit is contained in:
Brian Burkhalter 2018-03-29 12:38:47 -07:00
parent aa69f8c75c
commit dee3c23d5b

View File

@ -50,8 +50,8 @@ public class ReadAllReadNTransferTo {
ByteArrayInputStream bais =
new ByteArrayInputStream(buf, position, size);
int off = random.nextInt(size / 2);
int len = random.nextInt(size - off);
int off = size < 2 ? 0 : random.nextInt(size / 2);
int len = size - off < 1 ? 0 : random.nextInt(size - off);
byte[] bN = new byte[off + len];
if (bais.readNBytes(bN, off, len) != len) {