JDK 9 RFR of 8176394: Incorrect relational operator in java/nio/channels/FileChannel/InterruptDeadlock.java
Alan Bateman
Alan.Bateman at oracle.com
Wed Mar 8 19:13:39 UTC 2017
Looks right.
On 08/03/2017 19:12, Brian Burkhalter wrote:
> Please review the change below for [1]. The Reader thread run() method is supposed to read continuously from the FileChannel fc. However ‘pos’ will eventually equal fc.size() at which point fc.read() will always return -1 and ‘pos’ will not be reset to zero in contravention of the intent of the test.
>
> Thanks,
>
> Brian
>
> @@ -51,21 +51,21 @@
> public void run() {
> ByteBuffer bb = ByteBuffer.allocate(1024);
> try {
> long pos = 0L;
> for (;;) {
> bb.clear();
> int n = fc.read(bb, pos);
> if (n > 0)
> pos += n;
> // fc.size is important here as it is position sensitive
> - if (pos > fc.size())
> + if (pos >= fc.size())
> pos = 0L;
> }
> } catch (ClosedChannelException x) {
> System.out.println(x.getClass() + " (expected)");
> } catch (Exception unexpected) {
> this.exception = unexpected;
> }
> }
>
> [1] https://bugs.openjdk.java.net/browse/JDK-8176394
More information about the nio-dev
mailing list