8200449: ReadAllReadNTransferTo fails occasionally
authorbpb
Thu, 29 Mar 2018 12:38:47 -0700
changeset 49489 f5e614a1ed98
parent 49488 1f9dd2360b17
child 49490 1bc4cd2c5f8b
child 56373 1f76a5f8e999
8200449: ReadAllReadNTransferTo fails occasionally Summary: Don't pass a non-positive parameter to Random.nextInt(int). Reviewed-by: chegar
test/jdk/java/io/ByteArrayInputStream/ReadAllReadNTransferTo.java
--- a/test/jdk/java/io/ByteArrayInputStream/ReadAllReadNTransferTo.java	Sat Mar 24 01:08:35 2018 +0100
+++ b/test/jdk/java/io/ByteArrayInputStream/ReadAllReadNTransferTo.java	Thu Mar 29 12:38:47 2018 -0700
@@ -50,8 +50,8 @@
 
         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) {