RFR: 8189366: SocketInputStream.available() should check for eof

David Lloyd david.lloyd at redhat.com
Fri Oct 12 13:43:34 UTC 2018


On Fri, Oct 12, 2018 at 6:01 AM Chris Hegarty <chris.hegarty at oracle.com> wrote:
> That is correct. While not intuitive, I don't propose
> that we change this. ( if this were a new implementation
> then I think it should throw IOE for this scenario, but
> we are where we are ).

I am glad then that it is not a new implementation.  Returning an EOF
signal is a very reasonable behavior for a closed input stream or
input channel.  In most cases, it is more difficult for I/O handling
code to distinguish the two states (open+eof versus closed), and in
every case I've ever known, they are handled in the same way, or
intended to be.  There is no useful way I know of to exploit a side
effect of exception throwing in the read-on-closed case.

Also, I think it's a lot more reasonable for programs to expect that
available() will return 0 when the stream is closed than for
available() to be, in effect, an openness check.  Granted that
available() is not really useful anyway, but were one to use it,
having an extra failure state to deal with probably isn't helpful.

-- 
- DML


More information about the net-dev mailing list