FULL PRODUCT VERSION :
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
Input stream created by Channels.newInputStream(ReadableByteChannel ch) may work incorrecly with non-blocking channels.
According to method description "the read methods of the resulting stream will throw an IllegalBlockingModeException if invoked while the underlying channel is in non-blocking mode".
This check is performed only for instances of SelectableChannel. If channel doesn't extend it read() method of resulting InputStream works in non-blocking mode and returns -1 if data is not presently available.
This violates requirements for InputStream.read() - it must be blocking operation returning -1 only if end of stream is reached.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run test case.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
IllegalBlockingModeException on first read operation. ReadableByteChannel.read of blocking channel can't return 0, its either a positive number of bytes read or -1 for EOF.
ACTUAL -
Program prints:
-1
0
First indicates EOF for this stream, second - zero value read from stream after EOF.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.*;
import java.nio.*;
import java.nio.channels.*;
public class a implements ReadableByteChannel {
public static void main(String args[]) throws Exception {
InputStream is = Channels.newInputStream(new a());
System.out.println(is.read());
System.out.println(is.read());
}
int count;
public int read(ByteBuffer dst) {
count++;
if (count > 1) {
return 1;
}
return 0;
}
public void close() {}
public boolean isOpen() { return true;}
}
---------- END SOURCE ----------
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
Input stream created by Channels.newInputStream(ReadableByteChannel ch) may work incorrecly with non-blocking channels.
According to method description "the read methods of the resulting stream will throw an IllegalBlockingModeException if invoked while the underlying channel is in non-blocking mode".
This check is performed only for instances of SelectableChannel. If channel doesn't extend it read() method of resulting InputStream works in non-blocking mode and returns -1 if data is not presently available.
This violates requirements for InputStream.read() - it must be blocking operation returning -1 only if end of stream is reached.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run test case.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
IllegalBlockingModeException on first read operation. ReadableByteChannel.read of blocking channel can't return 0, its either a positive number of bytes read or -1 for EOF.
ACTUAL -
Program prints:
-1
0
First indicates EOF for this stream, second - zero value read from stream after EOF.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.*;
import java.nio.*;
import java.nio.channels.*;
public class a implements ReadableByteChannel {
public static void main(String args[]) throws Exception {
InputStream is = Channels.newInputStream(new a());
System.out.println(is.read());
System.out.println(is.read());
}
int count;
public int read(ByteBuffer dst) {
count++;
if (count > 1) {
return 1;
}
return 0;
}
public void close() {}
public boolean isOpen() { return true;}
}
---------- END SOURCE ----------
- relates to
-
JDK-7174305 (ch) Channels.newReader doesn't throw IllegalBlockingModeException if channel is configured non-blocking
-
- Resolved
-