InterruptedException and I/O?

R

Russell Gold

Are there any conditions under which it is sensible that an
InterruptedException would be thrown from
java.net.SocketOutputStream.socketWrite? I am seeing it on Windows (JRE
build 1.4.2_03-b02) in a case where an ObjectOutputStream attached to a
socket is flushed within a thread. I think that the other end of the
socket connection may be closed during the flush, but I would expect
InterruptedIOException in that case.
 
C

Chris Smith

Russell said:
Are there any conditions under which it is sensible that an
InterruptedException would be thrown from
java.net.SocketOutputStream.socketWrite? I am seeing it on Windows (JRE
build 1.4.2_03-b02) in a case where an ObjectOutputStream attached to a
socket is flushed within a thread. I think that the other end of the
socket connection may be closed during the flush, but I would expect
InterruptedIOException in that case.

java.net.SocketOutputStream is not a public API, so there's no right
answer regarding what can be thrown from it. I'm not aware of any
OuputStream class that should be throwing an InterruptedException,
though; in fact, since it's a checked exception, the compiler would
guarantee that this wouldn't happen.

Which public API is the exception coming from?

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
R

Russell Gold

Chris Smith said:
java.net.SocketOutputStream is not a public API, so there's no right
answer regarding what can be thrown from it. I'm not aware of any
OuputStream class that should be throwing an InterruptedException,
though; in fact, since it's a checked exception, the compiler would
guarantee that this wouldn't happen.

Which public API is the exception coming from?

OutputOutputStream.flush, in a case when it is connected to a socket
(see stack trace, below). This is not happening on Solaris.

java.lang.InterruptedException
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:66)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:124)
at
java.io_ObjectOutputStream$BlockDataOutputStream.flush(ObjectOutputStream
..java:1585)
at java.io_ObjectOutputStream.flush(ObjectOutputStream.java:639)
at com.x.server.rmi.RMICallHandler.run(RMICallHandler.java:182)
at com.x.server.rmi.RMICallHandler.run(RMICallHandler.java:48)
at
com.me.x.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResource
PooledExecutor.java:192)
04/02/10 18:21:49  at java.lang.Thread.run(Thread.java:534)
 
C

Chris Smith

Russell said:
OutputOutputStream.flush, in a case when it is connected to a socket
(see stack trace, below). This is not happening on Solaris.

[...]

I'd definitely report this as a bug, if you can come up with a
reproducible test case. It clearly shouldn't be the case. In fact,
double wammy because you have to play tricks for the compiler to even
let you catch the InterruptedException (i.e., it will claim that the
code in the try block couldn't possibly throw that exception and so the
catch block is unreachable.)

Of course, you can work around the latter problem with:

try
{
if (false) throw new InterruptedException();
...
}
catch (InterruptedException e)
{
...
}

But that's ugly. Definitely do the bug report.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top