diff --git a/src/main/java/org/jboss/netty/bootstrap/ClientBootstrap.java b/src/main/java/org/jboss/netty/bootstrap/ClientBootstrap.java index 41f67305b3..1a185aa986 100644 --- a/src/main/java/org/jboss/netty/bootstrap/ClientBootstrap.java +++ b/src/main/java/org/jboss/netty/bootstrap/ClientBootstrap.java @@ -267,8 +267,8 @@ public class ClientBootstrap extends Bootstrap { if (localAddress != null) { event.getChannel().bind(localAddress); } else { - futureQueue.offer(event.getChannel().connect(remoteAddress)); - finished = true; + finished = futureQueue.offer(event.getChannel().connect(remoteAddress)); + assert finished; } } @@ -280,8 +280,8 @@ public class ClientBootstrap extends Bootstrap { // Connect if not connected yet. if (localAddress != null) { - futureQueue.offer(event.getChannel().connect(remoteAddress)); - finished = true; + finished = futureQueue.offer(event.getChannel().connect(remoteAddress)); + assert finished; } } @@ -294,8 +294,8 @@ public class ClientBootstrap extends Bootstrap { Throwable cause = e.getCause(); if (!(cause instanceof NotYetConnectedException) && !finished) { e.getChannel().close(); - futureQueue.offer(failedFuture(e.getChannel(), cause)); - finished = true; + finished = futureQueue.offer(failedFuture(e.getChannel(), cause)); + assert finished; } } } diff --git a/src/main/java/org/jboss/netty/bootstrap/ServerBootstrap.java b/src/main/java/org/jboss/netty/bootstrap/ServerBootstrap.java index 903cbffa82..1aeb241330 100644 --- a/src/main/java/org/jboss/netty/bootstrap/ServerBootstrap.java +++ b/src/main/java/org/jboss/netty/bootstrap/ServerBootstrap.java @@ -300,7 +300,8 @@ public class ServerBootstrap extends Bootstrap { // Apply parent options. evt.getChannel().getConfig().setOptions(parentOptions); - futureQueue.offer(evt.getChannel().bind(localAddress)); + boolean finished = futureQueue.offer(evt.getChannel().bind(localAddress)); + assert finished; ctx.sendUpstream(evt); } diff --git a/src/main/java/org/jboss/netty/buffer/ReadOnlyChannelBuffer.java b/src/main/java/org/jboss/netty/buffer/ReadOnlyChannelBuffer.java index 6c5ff30838..e82860684d 100644 --- a/src/main/java/org/jboss/netty/buffer/ReadOnlyChannelBuffer.java +++ b/src/main/java/org/jboss/netty/buffer/ReadOnlyChannelBuffer.java @@ -27,6 +27,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import java.nio.ReadOnlyBufferException; import java.nio.channels.GatheringByteChannel; import java.nio.channels.ScatteringByteChannel; @@ -72,55 +73,49 @@ public class ReadOnlyChannelBuffer extends AbstractChannelBuffer implements Wrap @Override public void discardReadBytes() { - rejectModification(); + throw new ReadOnlyBufferException(); } public void setByte(int index, byte value) { - rejectModification(); + throw new ReadOnlyBufferException(); } public void setBytes(int index, ChannelBuffer src, int srcIndex, int length) { - rejectModification(); + throw new ReadOnlyBufferException(); } public void setBytes(int index, byte[] src, int srcIndex, int length) { - rejectModification(); + throw new ReadOnlyBufferException(); } public void setBytes(int index, ByteBuffer src) { - rejectModification(); + throw new ReadOnlyBufferException(); } public void setShort(int index, short value) { - rejectModification(); + throw new ReadOnlyBufferException(); } public void setMedium(int index, int value) { - rejectModification(); + throw new ReadOnlyBufferException(); } public void setInt(int index, int value) { - rejectModification(); + throw new ReadOnlyBufferException(); } public void setLong(int index, long value) { - rejectModification(); + throw new ReadOnlyBufferException(); } public int setBytes(int index, InputStream in, int length) throws IOException { - rejectModification(); - return 0; + throw new ReadOnlyBufferException(); } public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { - rejectModification(); - return 0; - } - - protected void rejectModification() { - throw new UnsupportedOperationException("read-only"); + throw new ReadOnlyBufferException(); } public int getBytes(int index, GatheringByteChannel out, int length) diff --git a/src/main/java/org/jboss/netty/channel/socket/nio/NioProviderMetadata.java b/src/main/java/org/jboss/netty/channel/socket/nio/NioProviderMetadata.java index 6ebb9ba500..5142740fad 100644 --- a/src/main/java/org/jboss/netty/channel/socket/nio/NioProviderMetadata.java +++ b/src/main/java/org/jboss/netty/channel/socket/nio/NioProviderMetadata.java @@ -240,7 +240,8 @@ class NioProviderMetadata { try { level = autodetectWithoutTimeout(); } finally { - resultQueue.offer(Integer.valueOf(level)); + boolean finished = resultQueue.offer(Integer.valueOf(level)); + assert finished; } } }, "NIO constraint level detector"); diff --git a/src/main/java/org/jboss/netty/example/factorial/FactorialClientHandler.java b/src/main/java/org/jboss/netty/example/factorial/FactorialClientHandler.java index 14779e297e..b523785db4 100644 --- a/src/main/java/org/jboss/netty/example/factorial/FactorialClientHandler.java +++ b/src/main/java/org/jboss/netty/example/factorial/FactorialClientHandler.java @@ -106,7 +106,8 @@ public class FactorialClientHandler extends SimpleChannelHandler { // Offer the answer after closing the connection. e.getChannel().close().addListener(new ChannelFutureListener() { public void operationComplete(ChannelFuture future) { - answer.offer((BigInteger) e.getMessage()); + boolean offered = answer.offer((BigInteger) e.getMessage()); + assert offered; } }); } diff --git a/src/main/java/org/jboss/netty/example/localtime/LocalTimeClientHandler.java b/src/main/java/org/jboss/netty/example/localtime/LocalTimeClientHandler.java index a8b5272bc5..0d854a9808 100644 --- a/src/main/java/org/jboss/netty/example/localtime/LocalTimeClientHandler.java +++ b/src/main/java/org/jboss/netty/example/localtime/LocalTimeClientHandler.java @@ -119,7 +119,8 @@ public class LocalTimeClientHandler extends SimpleChannelHandler { @Override public void messageReceived( ChannelHandlerContext ctx, final MessageEvent e) { - answer.offer((LocalTimes) e.getMessage()); + boolean offered = answer.offer((LocalTimes) e.getMessage()); + assert offered; } @Override diff --git a/src/main/java/org/jboss/netty/handler/codec/http/HttpMessageDecoder.java b/src/main/java/org/jboss/netty/handler/codec/http/HttpMessageDecoder.java index 0e012c26a0..ef36611dce 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/HttpMessageDecoder.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/HttpMessageDecoder.java @@ -92,9 +92,11 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder