changeset 47448:75c90020d8e0

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
author bpb
date Wed, 25 Oct 2017 16:13:53 -0700
parents 9887d1bc3e9c
children afa66f3c34c1
files test/jdk/java/nio/channels/FileChannel/directio/ReadDirect.java
diffstat 1 files changed, 6 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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);