8200449: ReadAllReadNTransferTo fails occasionally

Brian Burkhalter brian.burkhalter at oracle.com
Thu Mar 29 19:01:23 UTC 2018


https://bugs.openjdk.java.net/browse/JDK-8200449

Problem is due to passing zero to Random.nextInt(int). Diff included below.

Thanks,

Brian

--- a/test/jdk/java/io/ByteArrayInputStream/ReadAllReadNTransferTo.java
+++ b/test/jdk/java/io/ByteArrayInputStream/ReadAllReadNTransferTo.java
@@ -43,22 +43,22 @@
     private static Random random = RandomFactory.getRandom();
 
     public static void main(String... args) throws IOException {
         byte[] buf = new byte[SIZE];
         random.nextBytes(buf);
         int position = random.nextInt(SIZE/2);
         int size = random.nextInt(SIZE - position);
 
         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) {
             throw new RuntimeException("readNBytes return value");
         }
         if (!Arrays.equals(bN, off, off + len,
             buf, position, position + len)) {
             throw new RuntimeException("readNBytes content");
         }



More information about the core-libs-dev mailing list