Author: remm Date: Fri Mar 14 12:09:48 2014 New Revision: 1577501 URL: http://svn.apache.org/r1577501 Log: Start harmonizing exception types (todo: same thing for completion handlers).
Modified: tomcat/trunk/java/org/apache/coyote/http11/InternalNio2InputBuffer.java tomcat/trunk/java/org/apache/coyote/http11/InternalNio2OutputBuffer.java tomcat/trunk/java/org/apache/coyote/http11/upgrade/Nio2ServletInputStream.java tomcat/trunk/java/org/apache/coyote/http11/upgrade/Nio2ServletOutputStream.java Modified: tomcat/trunk/java/org/apache/coyote/http11/InternalNio2InputBuffer.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/InternalNio2InputBuffer.java?rev=1577501&r1=1577500&r2=1577501&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http11/InternalNio2InputBuffer.java (original) +++ tomcat/trunk/java/org/apache/coyote/http11/InternalNio2InputBuffer.java Fri Mar 14 12:09:48 2014 @@ -18,8 +18,8 @@ package org.apache.coyote.http11; import java.io.EOFException; import java.io.IOException; +import java.net.SocketTimeoutException; import java.nio.ByteBuffer; -import java.nio.channels.ClosedChannelException; import java.nio.channels.CompletionHandler; import java.nio.channels.ReadPendingException; import java.nio.charset.StandardCharsets; @@ -754,7 +754,7 @@ public class InternalNio2InputBuffer ext boolean notify = false; synchronized (completionHandler) { if (nBytes.intValue() < 0) { - failed(new ClosedChannelException(), attachment); + failed(new EOFException(sm.getString("iib.eof.error")), attachment); return; } readPending = false; @@ -819,9 +819,10 @@ public class InternalNio2InputBuffer ext try { nRead = socket.getSocket().read(byteBuffer) .get(socket.getTimeout(), TimeUnit.MILLISECONDS).intValue(); - } catch (InterruptedException | ExecutionException - | TimeoutException e) { - throw new EOFException(sm.getString("iib.eof.error")); + } catch (InterruptedException | ExecutionException e) { + throw new IOException(e); + } catch (TimeoutException e) { + throw new SocketTimeoutException(); } if (nRead > 0) { if (!flipped) { Modified: tomcat/trunk/java/org/apache/coyote/http11/InternalNio2OutputBuffer.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/InternalNio2OutputBuffer.java?rev=1577501&r1=1577500&r2=1577501&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http11/InternalNio2OutputBuffer.java (original) +++ tomcat/trunk/java/org/apache/coyote/http11/InternalNio2OutputBuffer.java Fri Mar 14 12:09:48 2014 @@ -17,6 +17,7 @@ package org.apache.coyote.http11; +import java.io.EOFException; import java.io.IOException; import java.net.SocketTimeoutException; import java.nio.ByteBuffer; @@ -116,7 +117,7 @@ public class InternalNio2OutputBuffer ex boolean notify = false; synchronized (completionHandler) { if (nBytes.intValue() < 0) { - failed(new IOException(sm.getString("iob.failedwrite")), attachment); + failed(new EOFException(sm.getString("iob.failedwrite")), attachment); return; } if (bufferedWrites.size() > 0) { @@ -163,7 +164,7 @@ public class InternalNio2OutputBuffer ex boolean notify = false; synchronized (completionHandler) { if (nBytes.longValue() < 0) { - failed(new IOException(sm.getString("iob.failedwrite")), attachment); + failed(new EOFException(sm.getString("iob.failedwrite")), attachment); return; } if (bufferedWrites.size() > 0 || arrayHasData(attachment)) { @@ -381,9 +382,7 @@ public class InternalNio2OutputBuffer ex flipped = true; } socket.getSocket().write(byteBuffer).get(socket.getTimeout(), TimeUnit.MILLISECONDS); - } catch (InterruptedException e) { - throw new IOException(e); - } catch (ExecutionException e) { + } catch (InterruptedException | ExecutionException e) { throw new IOException(e); } catch (TimeoutException e) { throw new SocketTimeoutException(); Modified: tomcat/trunk/java/org/apache/coyote/http11/upgrade/Nio2ServletInputStream.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/upgrade/Nio2ServletInputStream.java?rev=1577501&r1=1577500&r2=1577501&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http11/upgrade/Nio2ServletInputStream.java (original) +++ tomcat/trunk/java/org/apache/coyote/http11/upgrade/Nio2ServletInputStream.java Fri Mar 14 12:09:48 2014 @@ -18,9 +18,9 @@ package org.apache.coyote.http11.upgrade import java.io.EOFException; import java.io.IOException; +import java.net.SocketTimeoutException; import java.nio.ByteBuffer; import java.nio.channels.AsynchronousCloseException; -import java.nio.channels.ClosedChannelException; import java.nio.channels.CompletionHandler; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -50,7 +50,7 @@ public class Nio2ServletInputStream exte public void completed(Integer nBytes, SocketWrapper<Nio2Channel> attachment) { synchronized (completionHandler) { if (nBytes.intValue() < 0) { - failed(new ClosedChannelException(), attachment); + failed(new EOFException(), attachment); return; } readPending = false; @@ -207,10 +207,13 @@ public class Nio2ServletInputStream exte nRead = channel.read(readBuffer) .get(wrapper.getTimeout(), TimeUnit.MILLISECONDS).intValue(); readPending = false; - } catch (InterruptedException | ExecutionException - | TimeoutException e) { + } catch (InterruptedException | ExecutionException e) { onError(e); throw new IOException(e); + } catch (TimeoutException e) { + SocketTimeoutException ex = new SocketTimeoutException(); + onError(ex); + throw ex; } } else { readPending = true; Modified: tomcat/trunk/java/org/apache/coyote/http11/upgrade/Nio2ServletOutputStream.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/upgrade/Nio2ServletOutputStream.java?rev=1577501&r1=1577500&r2=1577501&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http11/upgrade/Nio2ServletOutputStream.java (original) +++ tomcat/trunk/java/org/apache/coyote/http11/upgrade/Nio2ServletOutputStream.java Fri Mar 14 12:09:48 2014 @@ -18,9 +18,9 @@ package org.apache.coyote.http11.upgrade import java.io.EOFException; import java.io.IOException; +import java.net.SocketTimeoutException; import java.nio.ByteBuffer; import java.nio.channels.AsynchronousCloseException; -import java.nio.channels.ClosedChannelException; import java.nio.channels.CompletionHandler; import java.util.concurrent.ExecutionException; import java.util.concurrent.Semaphore; @@ -50,7 +50,7 @@ public class Nio2ServletOutputStream ext @Override public void completed(Integer nBytes, SocketWrapper<Nio2Channel> attachment) { if (nBytes.intValue() < 0) { - failed(new ClosedChannelException(), attachment); + failed(new EOFException(), attachment); return; } writePending.release(); @@ -126,10 +126,13 @@ public class Nio2ServletOutputStream ext buffer.flip(); try { written = channel.write(buffer).get(socketWrapper.getTimeout(), TimeUnit.MILLISECONDS).intValue(); - } catch (InterruptedException | ExecutionException - | TimeoutException e) { + } catch (InterruptedException | ExecutionException e) { onError(e); throw new IOException(e); + } catch (TimeoutException e) { + SocketTimeoutException ex = new SocketTimeoutException(); + onError(ex); + throw ex; } } else { if (writePending.tryAcquire()) { @@ -152,10 +155,16 @@ public class Nio2ServletOutputStream ext if (writePending.tryAcquire(socketWrapper.getTimeout(), TimeUnit.MILLISECONDS)) { writePending.release(); channel.flush().get(socketWrapper.getTimeout(), TimeUnit.MILLISECONDS); + } else { + throw new TimeoutException(); } - } catch (InterruptedException | ExecutionException | TimeoutException e) { + } catch (InterruptedException | ExecutionException e) { onError(e); throw new IOException(e); + } catch (TimeoutException e) { + SocketTimeoutException ex = new SocketTimeoutException(); + onError(ex); + throw ex; } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org