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
--- 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);