changeset 49578:f5e614a1ed98

8200449: ReadAllReadNTransferTo fails occasionally Summary: Don't pass a non-positive parameter to Random.nextInt(int). Reviewed-by: chegar
author bpb
date Thu, 29 Mar 2018 12:38:47 -0700
parents 1f9dd2360b17
children 1bc4cd2c5f8b
files test/jdk/java/io/ByteArrayInputStream/ReadAllReadNTransferTo.java
diffstat 1 files changed, 2 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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) {