8189775: java/nio/channels/FileChannel/directio/ReadDirect.java failed with NumberFormatException
authorbpb
Wed, 25 Oct 2017 16:13:53 -0700
changeset 47448 75c90020d8e0
parent 47447 9887d1bc3e9c
child 47449 afa66f3c34c1
8189775: java/nio/channels/FileChannel/directio/ReadDirect.java failed with NumberFormatException Summary: Clamp the offset so the scattering read remains within the channel. Reviewed-by: rriggs
test/jdk/java/nio/channels/FileChannel/directio/ReadDirect.java
--- a/test/jdk/java/nio/channels/FileChannel/directio/ReadDirect.java	Wed Oct 25 12:29:00 2017 -0700
+++ b/test/jdk/java/nio/channels/FileChannel/directio/ReadDirect.java	Wed Oct 25 16:13:53 2017 -0700
@@ -177,7 +177,12 @@
                 }
             }
 
-            randomNumber = generator.nextInt(100);
+            // The size of the test FileChannel is 100*charsPerGroup.
+            // As the channel bytes will be scattered into two buffers
+            // each of size charsPerGroup, the offset cannot be greater
+            // than 98*charsPerGroup, so the value of randomNumber must
+            // be in the range [0,98], i.e., 0 <= randomNumber < 99.
+            randomNumber = generator.nextInt(99);
             long offset =  randomNumber * charsPerGroup;
             fc.position(offset);
             fc.read(dests, 1, 2);