What happens if a Channel is read after being closed?

Alan Bateman Alan.Bateman at Sun.COM
Thu Aug 27 10:31:35 PDT 2009


Gili wrote:
> Oops, AsynchronousChannel.close()'s Javadoc reads:
>
> "further attempts to initiate asynchronous I/O operations complete
> immediately with cause ClosedChannelException."
>
> That being said, shouldn't the read/write methods still document this as an
> exception that may be thrown?
>
>   
The read/write methods don't throw I/O exceptions or any checked 
exception, at least not directly. Instead the I/O operation completes 
immediately with ClosedChannelException. So where you use a 
CompletionHandler, its failed method is invoked with the 
ClosedChannelException. If using a Future then its get method throws 
ExecutionException with ClosedChannelException as the cause. I agree 
this isn't obvious from just looking at the specific I/O methods so I'll 
look into how we might improve this.

-Alan



More information about the nio-discuss mailing list