From 6ac8ef54f7c7c4d7708285a9248f37efe3dae495 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Thu, 8 Jul 2021 10:16:00 +0200 Subject: [PATCH] =?UTF-8?q?Remove=20`throws=20Exception`=20from=20`Channel?= =?UTF-8?q?Handler`=20methods=20that=20handle=20o=E2=80=A6=20(#11417)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Motivation: At the moment all methods in `ChannelHandler` declare `throws Exception` as part of their method signature. While this is fine for methods that handle inbound events it is quite confusing for methods that handle outbound events. This comes due the fact that these methods also take a `ChannelPromise` which actually need to be fullfilled to signal back either success or failure. Define `throws...` for these methods is confusing at best. We should just always require the implementation to use the passed in promise to signal back success or failure. Doing so also clears up semantics in general. Due the fact that we can't "forbid" throwing `RuntimeException` we still need to handle this in some way tho. In this case we should just consider it a "bug" and so log it and close the `Channel` in question. The user should never have an exception "escape" their implementation and just use the promise. This also clears up the ownership of the passed in message etc. As `flush(ChannelHandlerContext)` and `read(ChannelHandlerContext)` don't take a `ChannelPromise` as argument this also means that these methods can never produce an error. This makes kind of sense as these really are just "signals" for the underlying transports to do something. For `RuntimeException` the same rule is used as for other outbound event handling methods, which is logging and closing the `Channel`. Motifications: - Remove `throws Exception` from signature - Adjust code to not throw and just notify the promise directly - Adjust unit tests Result: Much cleaner API and semantics. --- .../codec/http/HttpClientUpgradeHandler.java | 17 +++--- .../http/HttpServerKeepAliveHandler.java | 2 +- .../handler/codec/http/cors/CorsHandler.java | 3 +- .../websocketx/WebSocketProtocolHandler.java | 4 +- .../WebSocketClientExtensionHandler.java | 2 +- .../WebSocketServerExtensionHandler.java | 2 +- .../WebSocketHandshakeHandOverTest.java | 1 - .../codec/http2/Http2ConnectionHandler.java | 14 ++--- .../handler/codec/http2/Http2FrameCodec.java | 2 +- .../http2/Http2ConnectionRoundtripTest.java | 13 +++-- .../codec/http2/Http2MultiplexTest.java | 2 +- ...Http2StreamFrameToHttpObjectCodecTest.java | 2 +- .../handler/codec/ByteToMessageCodec.java | 2 +- .../handler/codec/DatagramPacketEncoder.java | 12 ++--- .../handler/codec/MessageToByteEncoder.java | 6 +-- .../handler/codec/MessageToMessageCodec.java | 2 +- .../codec/MessageToMessageEncoder.java | 6 +-- .../codec/compression/Bzip2Encoder.java | 2 +- .../codec/compression/JdkZlibEncoder.java | 2 +- .../codec/compression/Lz4FrameEncoder.java | 4 +- .../netty/example/haproxy/HAProxyHandler.java | 2 +- .../netty/handler/proxy/HttpProxyHandler.java | 14 ++--- .../io/netty/handler/proxy/ProxyHandler.java | 6 +-- .../address/ResolveAddressHandler.java | 6 +-- .../flush/FlushConsolidationHandler.java | 10 ++-- .../netty/handler/logging/LoggingHandler.java | 14 ++--- .../netty/handler/pcap/PcapWriteHandler.java | 2 +- .../java/io/netty/handler/ssl/SslHandler.java | 24 ++++----- .../handler/stream/ChunkedWriteHandler.java | 4 +- .../handler/timeout/IdleStateHandler.java | 2 +- .../handler/timeout/WriteTimeoutHandler.java | 2 +- .../AbstractTrafficShapingHandler.java | 3 +- .../GlobalChannelTrafficShapingHandler.java | 3 +- .../flush/FlushConsolidationHandlerTest.java | 2 +- .../io/netty/handler/ssl/SslHandlerTest.java | 2 +- .../stream/ChunkedWriteHandlerTest.java | 2 +- .../epoll/EpollSocketChannelBenchmark.java | 3 +- .../java/io/netty/channel/ChannelHandler.java | 26 ++++------ .../channel/CombinedChannelDuplexHandler.java | 16 +++--- .../channel/DefaultChannelHandlerContext.java | 52 ++++++++++--------- .../io/netty/bootstrap/BootstrapTest.java | 2 +- .../channel/DefaultChannelPipelineTest.java | 2 +- .../java/io/netty/channel/LoggingHandler.java | 17 +++--- .../netty/channel/PendingWriteQueueTest.java | 10 ++-- .../netty/channel/ReentrantChannelTest.java | 16 ++---- .../channel/embedded/EmbeddedChannelTest.java | 18 +++---- 46 files changed, 172 insertions(+), 188 deletions(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpClientUpgradeHandler.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpClientUpgradeHandler.java index eb4162ce74..3b6b934f6b 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpClientUpgradeHandler.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpClientUpgradeHandler.java @@ -121,33 +121,33 @@ public class HttpClientUpgradeHandler extends HttpObjectAggregator { } @Override - public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) throws Exception { + public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) { ctx.bind(localAddress, promise); } @Override public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, - ChannelPromise promise) throws Exception { + ChannelPromise promise) { ctx.connect(remoteAddress, localAddress, promise); } @Override - public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { + public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) { ctx.disconnect(promise); } @Override - public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { + public void close(ChannelHandlerContext ctx, ChannelPromise promise) { ctx.close(promise); } @Override - public void register(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { + public void register(ChannelHandlerContext ctx, ChannelPromise promise) { ctx.register(promise); } @Override - public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { + public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) { ctx.deregister(promise); } @@ -157,8 +157,7 @@ public class HttpClientUpgradeHandler extends HttpObjectAggregator { } @Override - public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) - throws Exception { + public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { if (!(msg instanceof HttpRequest)) { ctx.write(msg, promise); return; @@ -182,7 +181,7 @@ public class HttpClientUpgradeHandler extends HttpObjectAggregator { } @Override - public void flush(ChannelHandlerContext ctx) throws Exception { + public void flush(ChannelHandlerContext ctx) { ctx.flush(); } diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpServerKeepAliveHandler.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpServerKeepAliveHandler.java index 0a52f58b6f..635e29712f 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpServerKeepAliveHandler.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpServerKeepAliveHandler.java @@ -65,7 +65,7 @@ public class HttpServerKeepAliveHandler implements ChannelHandler { } @Override - public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { // modify message on way out to add headers if needed if (msg instanceof HttpResponse) { final HttpResponse response = (HttpResponse) msg; diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/cors/CorsHandler.java b/codec-http/src/main/java/io/netty/handler/codec/http/cors/CorsHandler.java index 38b3fe0fd7..79557b7c11 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/cors/CorsHandler.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/cors/CorsHandler.java @@ -215,8 +215,7 @@ public class CorsHandler implements ChannelHandler { } @Override - public void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) - throws Exception { + public void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) { if (config != null && config.isCorsSupportEnabled() && msg instanceof HttpResponse) { final HttpResponse response = (HttpResponse) msg; if (setOrigin(response)) { diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketProtocolHandler.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketProtocolHandler.java index 672cb646d2..edf4e2fd14 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketProtocolHandler.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketProtocolHandler.java @@ -82,7 +82,7 @@ abstract class WebSocketProtocolHandler extends MessageToMessageDecoder { } @Override - public void flush(ChannelHandlerContext ctx) throws Exception { + public void flush(ChannelHandlerContext ctx) { didFlush = true; ctx.flush(); } diff --git a/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2StreamFrameToHttpObjectCodecTest.java b/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2StreamFrameToHttpObjectCodecTest.java index 0e2eafa059..933a8c81b8 100644 --- a/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2StreamFrameToHttpObjectCodecTest.java +++ b/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2StreamFrameToHttpObjectCodecTest.java @@ -454,7 +454,7 @@ public class Http2StreamFrameToHttpObjectCodecTest { EmbeddedChannel ch = new EmbeddedChannel(ctx.newHandler(ByteBufAllocator.DEFAULT), new ChannelHandler() { @Override - public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { if (msg instanceof Http2StreamFrame) { frames.add((Http2StreamFrame) msg); ctx.write(Unpooled.EMPTY_BUFFER, promise); diff --git a/codec/src/main/java/io/netty/handler/codec/ByteToMessageCodec.java b/codec/src/main/java/io/netty/handler/codec/ByteToMessageCodec.java index 472625939e..3cfeabfb2f 100644 --- a/codec/src/main/java/io/netty/handler/codec/ByteToMessageCodec.java +++ b/codec/src/main/java/io/netty/handler/codec/ByteToMessageCodec.java @@ -102,7 +102,7 @@ public abstract class ByteToMessageCodec extends ChannelHandlerAdapter { } @Override - public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { encoder.write(ctx, msg, promise); } diff --git a/codec/src/main/java/io/netty/handler/codec/DatagramPacketEncoder.java b/codec/src/main/java/io/netty/handler/codec/DatagramPacketEncoder.java index 4772d95d51..f03c45552d 100644 --- a/codec/src/main/java/io/netty/handler/codec/DatagramPacketEncoder.java +++ b/codec/src/main/java/io/netty/handler/codec/DatagramPacketEncoder.java @@ -91,29 +91,29 @@ public class DatagramPacketEncoder extends MessageToMessageEncoder extends MessageToMessageEncoder extends ChannelHandlerAdapter { } @Override - public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { ByteBuf buf = null; try { if (acceptOutboundMessage(msg)) { @@ -120,9 +120,9 @@ public abstract class MessageToByteEncoder extends ChannelHandlerAdapter { ctx.write(msg, promise); } } catch (EncoderException e) { - throw e; + promise.setFailure(e); } catch (Throwable e) { - throw new EncoderException(e); + promise.setFailure(new EncoderException(e)); } finally { if (buf != null) { buf.release(); diff --git a/codec/src/main/java/io/netty/handler/codec/MessageToMessageCodec.java b/codec/src/main/java/io/netty/handler/codec/MessageToMessageCodec.java index 8f4fc60786..b06010d857 100644 --- a/codec/src/main/java/io/netty/handler/codec/MessageToMessageCodec.java +++ b/codec/src/main/java/io/netty/handler/codec/MessageToMessageCodec.java @@ -112,7 +112,7 @@ public abstract class MessageToMessageCodec extends Cha } @Override - public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { encoder.write(ctx, msg, promise); } diff --git a/codec/src/main/java/io/netty/handler/codec/MessageToMessageEncoder.java b/codec/src/main/java/io/netty/handler/codec/MessageToMessageEncoder.java index 5d563da45c..e9aaf0223b 100644 --- a/codec/src/main/java/io/netty/handler/codec/MessageToMessageEncoder.java +++ b/codec/src/main/java/io/netty/handler/codec/MessageToMessageEncoder.java @@ -78,7 +78,7 @@ public abstract class MessageToMessageEncoder extends ChannelHandlerAdapter { } @Override - public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { CodecOutputList out = null; try { if (acceptOutboundMessage(msg)) { @@ -99,9 +99,9 @@ public abstract class MessageToMessageEncoder extends ChannelHandlerAdapter { ctx.write(msg, promise); } } catch (EncoderException e) { - throw e; + promise.setFailure(e); } catch (Throwable t) { - throw new EncoderException(t); + promise.setFailure(new EncoderException(t)); } finally { if (out != null) { try { diff --git a/codec/src/main/java/io/netty/handler/codec/compression/Bzip2Encoder.java b/codec/src/main/java/io/netty/handler/codec/compression/Bzip2Encoder.java index 39381727dd..127ea8e6a8 100644 --- a/codec/src/main/java/io/netty/handler/codec/compression/Bzip2Encoder.java +++ b/codec/src/main/java/io/netty/handler/codec/compression/Bzip2Encoder.java @@ -193,7 +193,7 @@ public class Bzip2Encoder extends MessageToByteEncoder { } @Override - public void close(final ChannelHandlerContext ctx, final ChannelPromise promise) throws Exception { + public void close(final ChannelHandlerContext ctx, final ChannelPromise promise) { ChannelFuture f = finishEncode(ctx, ctx.newPromise()); f.addListener((ChannelFutureListener) f1 -> ctx.close(promise)); diff --git a/codec/src/main/java/io/netty/handler/codec/compression/JdkZlibEncoder.java b/codec/src/main/java/io/netty/handler/codec/compression/JdkZlibEncoder.java index c95a4d10e0..70fb97eace 100644 --- a/codec/src/main/java/io/netty/handler/codec/compression/JdkZlibEncoder.java +++ b/codec/src/main/java/io/netty/handler/codec/compression/JdkZlibEncoder.java @@ -262,7 +262,7 @@ public class JdkZlibEncoder extends ZlibEncoder { } @Override - public void close(final ChannelHandlerContext ctx, final ChannelPromise promise) throws Exception { + public void close(final ChannelHandlerContext ctx, final ChannelPromise promise) { ChannelFuture f = finishEncode(ctx, ctx.newPromise()); f.addListener((ChannelFutureListener) f1 -> ctx.close(promise)); diff --git a/codec/src/main/java/io/netty/handler/codec/compression/Lz4FrameEncoder.java b/codec/src/main/java/io/netty/handler/codec/compression/Lz4FrameEncoder.java index dba38b3e1e..5efdbceaf7 100644 --- a/codec/src/main/java/io/netty/handler/codec/compression/Lz4FrameEncoder.java +++ b/codec/src/main/java/io/netty/handler/codec/compression/Lz4FrameEncoder.java @@ -297,7 +297,7 @@ public class Lz4FrameEncoder extends MessageToByteEncoder { } @Override - public void flush(final ChannelHandlerContext ctx) throws Exception { + public void flush(final ChannelHandlerContext ctx) { if (buffer != null && buffer.isReadable()) { final ByteBuf buf = allocateBuffer(ctx, Unpooled.EMPTY_BUFFER, isPreferDirect(), false); flushBufferedData(buf); @@ -366,7 +366,7 @@ public class Lz4FrameEncoder extends MessageToByteEncoder { } @Override - public void close(final ChannelHandlerContext ctx, final ChannelPromise promise) throws Exception { + public void close(final ChannelHandlerContext ctx, final ChannelPromise promise) { ChannelFuture f = finishEncode(ctx, ctx.newPromise()); f.addListener((ChannelFutureListener) f1 -> ctx.close(promise)); diff --git a/example/src/main/java/io/netty/example/haproxy/HAProxyHandler.java b/example/src/main/java/io/netty/example/haproxy/HAProxyHandler.java index 280e0613bb..37ec0efad4 100644 --- a/example/src/main/java/io/netty/example/haproxy/HAProxyHandler.java +++ b/example/src/main/java/io/netty/example/haproxy/HAProxyHandler.java @@ -33,7 +33,7 @@ public class HAProxyHandler extends ChannelOutboundHandlerAdapter { } @Override - public void write(final ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + public void write(final ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { ChannelFuture future = ctx.write(msg, promise); if (msg instanceof HAProxyMessage) { future.addListener(new ChannelFutureListener() { diff --git a/handler-proxy/src/main/java/io/netty/handler/proxy/HttpProxyHandler.java b/handler-proxy/src/main/java/io/netty/handler/proxy/HttpProxyHandler.java index 4fb73a3ffa..143c1b04e5 100644 --- a/handler-proxy/src/main/java/io/netty/handler/proxy/HttpProxyHandler.java +++ b/handler-proxy/src/main/java/io/netty/handler/proxy/HttpProxyHandler.java @@ -286,28 +286,28 @@ public final class HttpProxyHandler extends ProxyHandler { @Override public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, - ChannelPromise promise) throws Exception { + ChannelPromise promise) { codec.bind(ctx, localAddress, promise); } @Override public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, - ChannelPromise promise) throws Exception { + ChannelPromise promise) { codec.connect(ctx, remoteAddress, localAddress, promise); } @Override - public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { + public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) { codec.disconnect(ctx, promise); } @Override - public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { + public void close(ChannelHandlerContext ctx, ChannelPromise promise) { codec.close(ctx, promise); } @Override - public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { + public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) { codec.deregister(ctx, promise); } @@ -317,12 +317,12 @@ public final class HttpProxyHandler extends ProxyHandler { } @Override - public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { codec.write(ctx, msg, promise); } @Override - public void flush(ChannelHandlerContext ctx) throws Exception { + public void flush(ChannelHandlerContext ctx) { codec.flush(ctx); } } diff --git a/handler-proxy/src/main/java/io/netty/handler/proxy/ProxyHandler.java b/handler-proxy/src/main/java/io/netty/handler/proxy/ProxyHandler.java index 377c2fd69e..9d256c3a19 100644 --- a/handler-proxy/src/main/java/io/netty/handler/proxy/ProxyHandler.java +++ b/handler-proxy/src/main/java/io/netty/handler/proxy/ProxyHandler.java @@ -167,7 +167,7 @@ public abstract class ProxyHandler implements ChannelHandler { @Override public final void connect( ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, - ChannelPromise promise) throws Exception { + ChannelPromise promise) { if (destinationAddress != null) { promise.setFailure(new ConnectionPendingException()); @@ -394,7 +394,7 @@ public abstract class ProxyHandler implements ChannelHandler { } @Override - public final void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + public final void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { if (finished) { writePendingWrites(); ctx.write(msg, promise); @@ -404,7 +404,7 @@ public abstract class ProxyHandler implements ChannelHandler { } @Override - public final void flush(ChannelHandlerContext ctx) throws Exception { + public final void flush(ChannelHandlerContext ctx) { if (finished) { writePendingWrites(); ctx.flush(); diff --git a/handler/src/main/java/io/netty/handler/address/ResolveAddressHandler.java b/handler/src/main/java/io/netty/handler/address/ResolveAddressHandler.java index c9bdeb86da..034529bc7f 100644 --- a/handler/src/main/java/io/netty/handler/address/ResolveAddressHandler.java +++ b/handler/src/main/java/io/netty/handler/address/ResolveAddressHandler.java @@ -28,8 +28,8 @@ import java.net.SocketAddress; /** * {@link ChannelHandler} which will resolve the {@link SocketAddress} that is passed to - * {@link #connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)} if it is not already resolved - * and the {@link AddressResolver} supports the type of {@link SocketAddress}. + * {@link ChannelHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)} if it is not + * already resolved and the {@link AddressResolver} supports the type of {@link SocketAddress}. */ @Sharable public class ResolveAddressHandler implements ChannelHandler { @@ -42,7 +42,7 @@ public class ResolveAddressHandler implements ChannelHandler { @Override public void connect(final ChannelHandlerContext ctx, SocketAddress remoteAddress, - final SocketAddress localAddress, final ChannelPromise promise) { + final SocketAddress localAddress, final ChannelPromise promise) { AddressResolver resolver = resolverGroup.getResolver(ctx.executor()); if (resolver.isSupported(remoteAddress) && !resolver.isResolved(remoteAddress)) { resolver.resolve(remoteAddress).addListener((FutureListener) future -> { diff --git a/handler/src/main/java/io/netty/handler/flush/FlushConsolidationHandler.java b/handler/src/main/java/io/netty/handler/flush/FlushConsolidationHandler.java index 9d63157545..2ccc80c458 100644 --- a/handler/src/main/java/io/netty/handler/flush/FlushConsolidationHandler.java +++ b/handler/src/main/java/io/netty/handler/flush/FlushConsolidationHandler.java @@ -36,8 +36,8 @@ import java.util.concurrent.Future; * in most cases (where write latency can be traded with throughput) a good idea to try to minimize flush operations * as much as possible. *

- * If a read loop is currently ongoing, {@link #flush(ChannelHandlerContext)} will not be passed on to the next - * {@link ChannelHandler} in the {@link ChannelPipeline}, as it will pick up any pending flushes when + * If a read loop is currently ongoing, {@link ChannelHandler#flush(ChannelHandlerContext)} will not be passed on to + * the next {@link ChannelHandler} in the {@link ChannelPipeline}, as it will pick up any pending flushes when * {@link #channelReadComplete(ChannelHandlerContext)} is triggered. * If no read loop is ongoing, the behavior depends on the {@code consolidateWhenNoReadInProgress} constructor argument: *

    @@ -114,7 +114,7 @@ public class FlushConsolidationHandler implements ChannelHandler { } @Override - public void flush(ChannelHandlerContext ctx) throws Exception { + public void flush(ChannelHandlerContext ctx) { if (readInProgress) { // If there is still a read in progress we are sure we will see a channelReadComplete(...) call. Thus // we only need to flush if we reach the explicitFlushAfterFlushes limit. @@ -155,14 +155,14 @@ public class FlushConsolidationHandler implements ChannelHandler { } @Override - public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { + public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) { // Try to flush one last time if flushes are pending before disconnect the channel. resetReadAndFlushIfNeeded(ctx); ctx.disconnect(promise); } @Override - public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { + public void close(ChannelHandlerContext ctx, ChannelPromise promise) { // Try to flush one last time if flushes are pending before close the channel. resetReadAndFlushIfNeeded(ctx); ctx.close(promise); diff --git a/handler/src/main/java/io/netty/handler/logging/LoggingHandler.java b/handler/src/main/java/io/netty/handler/logging/LoggingHandler.java index fa18fbf0d7..a4ae4c2f23 100644 --- a/handler/src/main/java/io/netty/handler/logging/LoggingHandler.java +++ b/handler/src/main/java/io/netty/handler/logging/LoggingHandler.java @@ -222,7 +222,7 @@ public class LoggingHandler implements ChannelHandler { } @Override - public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) throws Exception { + public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) { if (logger.isEnabled(internalLevel)) { logger.log(internalLevel, format(ctx, "BIND", localAddress)); } @@ -232,7 +232,7 @@ public class LoggingHandler implements ChannelHandler { @Override public void connect( ChannelHandlerContext ctx, - SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception { + SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) { if (logger.isEnabled(internalLevel)) { logger.log(internalLevel, format(ctx, "CONNECT", remoteAddress, localAddress)); } @@ -240,7 +240,7 @@ public class LoggingHandler implements ChannelHandler { } @Override - public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { + public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) { if (logger.isEnabled(internalLevel)) { logger.log(internalLevel, format(ctx, "DISCONNECT")); } @@ -248,7 +248,7 @@ public class LoggingHandler implements ChannelHandler { } @Override - public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { + public void close(ChannelHandlerContext ctx, ChannelPromise promise) { if (logger.isEnabled(internalLevel)) { logger.log(internalLevel, format(ctx, "CLOSE")); } @@ -256,7 +256,7 @@ public class LoggingHandler implements ChannelHandler { } @Override - public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { + public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) { if (logger.isEnabled(internalLevel)) { logger.log(internalLevel, format(ctx, "DEREGISTER")); } @@ -280,7 +280,7 @@ public class LoggingHandler implements ChannelHandler { } @Override - public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { if (logger.isEnabled(internalLevel)) { logger.log(internalLevel, format(ctx, "WRITE", msg)); } @@ -296,7 +296,7 @@ public class LoggingHandler implements ChannelHandler { } @Override - public void flush(ChannelHandlerContext ctx) throws Exception { + public void flush(ChannelHandlerContext ctx) { if (logger.isEnabled(internalLevel)) { logger.log(internalLevel, format(ctx, "FLUSH")); } diff --git a/handler/src/main/java/io/netty/handler/pcap/PcapWriteHandler.java b/handler/src/main/java/io/netty/handler/pcap/PcapWriteHandler.java index 2af0ce8eb1..690a5bdc1a 100644 --- a/handler/src/main/java/io/netty/handler/pcap/PcapWriteHandler.java +++ b/handler/src/main/java/io/netty/handler/pcap/PcapWriteHandler.java @@ -239,7 +239,7 @@ public final class PcapWriteHandler extends ChannelDuplexHandler implements Clos } @Override - public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { if (!isClosed) { if (ctx.channel() instanceof SocketChannel) { handleTCP(ctx, msg, true); diff --git a/handler/src/main/java/io/netty/handler/ssl/SslHandler.java b/handler/src/main/java/io/netty/handler/ssl/SslHandler.java index 993e1ab6d5..0ac50dd3f1 100644 --- a/handler/src/main/java/io/netty/handler/ssl/SslHandler.java +++ b/handler/src/main/java/io/netty/handler/ssl/SslHandler.java @@ -475,7 +475,8 @@ public class SslHandler extends ByteToMessageDecoder { * Sets the number of bytes to pass to each {@link SSLEngine#wrap(ByteBuffer[], int, int, ByteBuffer)} call. *

    * This value will partition data which is passed to write - * {@link #write(ChannelHandlerContext, Object, ChannelPromise)}. The partitioning will work as follows: + * {@link ChannelHandler#write(ChannelHandlerContext, Object, ChannelPromise)}. + * The partitioning will work as follows: *

      *
    • If {@code wrapDataSize <= 0} then we will write each data chunk as is.
    • *
    • If {@code wrapDataSize > data size} then we will attempt to aggregate multiple data chunks together.
    • @@ -700,35 +701,35 @@ public class SslHandler extends ByteToMessageDecoder { } @Override - public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) throws Exception { + public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) { ctx.bind(localAddress, promise); } @Override public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, - ChannelPromise promise) throws Exception { + ChannelPromise promise) { ctx.connect(remoteAddress, localAddress, promise); } @Override - public void register(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { + public void register(ChannelHandlerContext ctx, ChannelPromise promise) { ctx.register(promise); } @Override - public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { + public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) { ctx.deregister(promise); } @Override public void disconnect(final ChannelHandlerContext ctx, - final ChannelPromise promise) throws Exception { + final ChannelPromise promise) { closeOutboundAndChannel(ctx, promise, true); } @Override public void close(final ChannelHandlerContext ctx, - final ChannelPromise promise) throws Exception { + final ChannelPromise promise) { closeOutboundAndChannel(ctx, promise, false); } @@ -746,7 +747,7 @@ public class SslHandler extends ByteToMessageDecoder { } @Override - public void write(final ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + public void write(final ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { if (!(msg instanceof ByteBufConvertible)) { UnsupportedMessageTypeException exception = new UnsupportedMessageTypeException(msg, ByteBuf.class); ReferenceCountUtil.safeRelease(msg); @@ -760,7 +761,7 @@ public class SslHandler extends ByteToMessageDecoder { } @Override - public void flush(ChannelHandlerContext ctx) throws Exception { + public void flush(ChannelHandlerContext ctx) { // Do not encrypt the first write request if this handler is // created with startTLS flag turned on. if (startTls && !isStateSet(STATE_SENT_FIRST_MESSAGE)) { @@ -781,7 +782,6 @@ public class SslHandler extends ByteToMessageDecoder { wrapAndFlush(ctx); } catch (Throwable cause) { setHandshakeFailure(ctx, cause); - throw cause; } } @@ -1832,7 +1832,7 @@ public class SslHandler extends ByteToMessageDecoder { } private void closeOutboundAndChannel( - final ChannelHandlerContext ctx, final ChannelPromise promise, boolean disconnect) throws Exception { + final ChannelHandlerContext ctx, final ChannelPromise promise, boolean disconnect) { setState(STATE_OUTBOUND_CLOSED); engine.closeOutbound(); @@ -1868,7 +1868,7 @@ public class SslHandler extends ByteToMessageDecoder { } } - private void flush(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { + private void flush(ChannelHandlerContext ctx, ChannelPromise promise) { if (pendingUnencryptedWrites != null) { pendingUnencryptedWrites.add(Unpooled.EMPTY_BUFFER, promise); } else { diff --git a/handler/src/main/java/io/netty/handler/stream/ChunkedWriteHandler.java b/handler/src/main/java/io/netty/handler/stream/ChunkedWriteHandler.java index 47a7c75fb3..402edddbe0 100644 --- a/handler/src/main/java/io/netty/handler/stream/ChunkedWriteHandler.java +++ b/handler/src/main/java/io/netty/handler/stream/ChunkedWriteHandler.java @@ -114,12 +114,12 @@ public class ChunkedWriteHandler implements ChannelHandler { } @Override - public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { queue.add(new PendingWrite(msg, promise)); } @Override - public void flush(ChannelHandlerContext ctx) throws Exception { + public void flush(ChannelHandlerContext ctx) { doFlush(ctx); } diff --git a/handler/src/main/java/io/netty/handler/timeout/IdleStateHandler.java b/handler/src/main/java/io/netty/handler/timeout/IdleStateHandler.java index b610b0ca89..b1b6a1ee85 100644 --- a/handler/src/main/java/io/netty/handler/timeout/IdleStateHandler.java +++ b/handler/src/main/java/io/netty/handler/timeout/IdleStateHandler.java @@ -297,7 +297,7 @@ public class IdleStateHandler implements ChannelHandler { } @Override - public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { // Allow writing with void promise if handler is only configured for read timeout events. if (writerIdleTimeNanos > 0 || allIdleTimeNanos > 0) { ctx.write(msg, promise).addListener(writeListener); diff --git a/handler/src/main/java/io/netty/handler/timeout/WriteTimeoutHandler.java b/handler/src/main/java/io/netty/handler/timeout/WriteTimeoutHandler.java index 3a2ae86278..bdab40a1b3 100644 --- a/handler/src/main/java/io/netty/handler/timeout/WriteTimeoutHandler.java +++ b/handler/src/main/java/io/netty/handler/timeout/WriteTimeoutHandler.java @@ -104,7 +104,7 @@ public class WriteTimeoutHandler implements ChannelHandler { } @Override - public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { if (timeoutNanos > 0) { scheduleTimeout(ctx, promise); } diff --git a/handler/src/main/java/io/netty/handler/traffic/AbstractTrafficShapingHandler.java b/handler/src/main/java/io/netty/handler/traffic/AbstractTrafficShapingHandler.java index 971dc878ed..7a7635ebed 100644 --- a/handler/src/main/java/io/netty/handler/traffic/AbstractTrafficShapingHandler.java +++ b/handler/src/main/java/io/netty/handler/traffic/AbstractTrafficShapingHandler.java @@ -549,8 +549,7 @@ public abstract class AbstractTrafficShapingHandler implements ChannelHandler { } @Override - public void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) - throws Exception { + public void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) { long size = calculateSize(msg); long now = TrafficCounter.milliSecondFromNano(); if (size > 0) { diff --git a/handler/src/main/java/io/netty/handler/traffic/GlobalChannelTrafficShapingHandler.java b/handler/src/main/java/io/netty/handler/traffic/GlobalChannelTrafficShapingHandler.java index b363031488..cebaf4f2ff 100644 --- a/handler/src/main/java/io/netty/handler/traffic/GlobalChannelTrafficShapingHandler.java +++ b/handler/src/main/java/io/netty/handler/traffic/GlobalChannelTrafficShapingHandler.java @@ -648,8 +648,7 @@ public class GlobalChannelTrafficShapingHandler extends AbstractTrafficShapingHa } @Override - public void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) - throws Exception { + public void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) { long size = calculateSize(msg); long now = TrafficCounter.milliSecondFromNano(); if (size > 0) { diff --git a/handler/src/test/java/io/netty/handler/flush/FlushConsolidationHandlerTest.java b/handler/src/test/java/io/netty/handler/flush/FlushConsolidationHandlerTest.java index 0261525f54..ef7d7aaeae 100644 --- a/handler/src/test/java/io/netty/handler/flush/FlushConsolidationHandlerTest.java +++ b/handler/src/test/java/io/netty/handler/flush/FlushConsolidationHandlerTest.java @@ -182,7 +182,7 @@ public class FlushConsolidationHandlerTest { return new EmbeddedChannel( new ChannelHandler() { @Override - public void flush(ChannelHandlerContext ctx) throws Exception { + public void flush(ChannelHandlerContext ctx) { flushCount.incrementAndGet(); ctx.flush(); } diff --git a/handler/src/test/java/io/netty/handler/ssl/SslHandlerTest.java b/handler/src/test/java/io/netty/handler/ssl/SslHandlerTest.java index 7e962f2b16..a741b6ab63 100644 --- a/handler/src/test/java/io/netty/handler/ssl/SslHandlerTest.java +++ b/handler/src/test/java/io/netty/handler/ssl/SslHandlerTest.java @@ -118,7 +118,7 @@ public class SslHandlerTest { SSLEngine engine = newClientModeSSLEngine(); SslHandler handler = new SslHandler(engine) { @Override - public void write(final ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + public void write(final ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { super.write(ctx, msg, promise); writeLatch.countDown(); } diff --git a/handler/src/test/java/io/netty/handler/stream/ChunkedWriteHandlerTest.java b/handler/src/test/java/io/netty/handler/stream/ChunkedWriteHandlerTest.java index a637a3bec2..74dc5ba7e3 100644 --- a/handler/src/test/java/io/netty/handler/stream/ChunkedWriteHandlerTest.java +++ b/handler/src/test/java/io/netty/handler/stream/ChunkedWriteHandlerTest.java @@ -616,7 +616,7 @@ public class ChunkedWriteHandlerTest { EmbeddedChannel ch = new EmbeddedChannel(new ChannelHandler() { @Override - public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { ReferenceCountUtil.release(msg); // Calling close so we will drop all queued messages in the ChunkedWriteHandler. ctx.close(); diff --git a/microbench/src/main/java/io/netty/microbench/channel/epoll/EpollSocketChannelBenchmark.java b/microbench/src/main/java/io/netty/microbench/channel/epoll/EpollSocketChannelBenchmark.java index 49954dd1d8..8c87e8c653 100644 --- a/microbench/src/main/java/io/netty/microbench/channel/epoll/EpollSocketChannelBenchmark.java +++ b/microbench/src/main/java/io/netty/microbench/channel/epoll/EpollSocketChannelBenchmark.java @@ -104,8 +104,7 @@ public class EpollSocketChannelBenchmark extends AbstractMicrobenchmark { } @Override - public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) - throws Exception { + public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { if (lastWritePromise != null) { throw new IllegalStateException(); } diff --git a/transport/src/main/java/io/netty/channel/ChannelHandler.java b/transport/src/main/java/io/netty/channel/ChannelHandler.java index 3544a0c324..7144c3ad67 100644 --- a/transport/src/main/java/io/netty/channel/ChannelHandler.java +++ b/transport/src/main/java/io/netty/channel/ChannelHandler.java @@ -278,10 +278,9 @@ public interface ChannelHandler { * @param ctx the {@link ChannelHandlerContext} for which the bind operation is made * @param localAddress the {@link SocketAddress} to which it should bound * @param promise the {@link ChannelPromise} to notify once the operation completes - * @throws Exception thrown if an error occurs */ @Skip - default void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) throws Exception { + default void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) { ctx.bind(localAddress, promise); } @@ -292,12 +291,11 @@ public interface ChannelHandler { * @param remoteAddress the {@link SocketAddress} to which it should connect * @param localAddress the {@link SocketAddress} which is used as source on connect * @param promise the {@link ChannelPromise} to notify once the operation completes - * @throws Exception thrown if an error occurs */ @Skip default void connect( ChannelHandlerContext ctx, SocketAddress remoteAddress, - SocketAddress localAddress, ChannelPromise promise) throws Exception { + SocketAddress localAddress, ChannelPromise promise) { ctx.connect(remoteAddress, localAddress, promise); } @@ -306,10 +304,9 @@ public interface ChannelHandler { * * @param ctx the {@link ChannelHandlerContext} for which the disconnect operation is made * @param promise the {@link ChannelPromise} to notify once the operation completes - * @throws Exception thrown if an error occurs */ @Skip - default void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { + default void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) { ctx.disconnect(promise); } @@ -318,10 +315,9 @@ public interface ChannelHandler { * * @param ctx the {@link ChannelHandlerContext} for which the close operation is made * @param promise the {@link ChannelPromise} to notify once the operation completes - * @throws Exception thrown if an error occurs */ @Skip - default void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { + default void close(ChannelHandlerContext ctx, ChannelPromise promise) { ctx.close(promise); } @@ -330,10 +326,9 @@ public interface ChannelHandler { * * @param ctx the {@link ChannelHandlerContext} for which the register operation is made * @param promise the {@link ChannelPromise} to notify once the operation completes - * @throws Exception thrown if an error occurs */ @Skip - default void register(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { + default void register(ChannelHandlerContext ctx, ChannelPromise promise) { ctx.register(promise); } @@ -342,10 +337,9 @@ public interface ChannelHandler { * * @param ctx the {@link ChannelHandlerContext} for which the deregister operation is made * @param promise the {@link ChannelPromise} to notify once the operation completes - * @throws Exception thrown if an error occurs */ @Skip - default void deregister(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { + default void deregister(ChannelHandlerContext ctx, ChannelPromise promise) { ctx.deregister(promise); } @@ -360,15 +354,14 @@ public interface ChannelHandler { /** * Called once a write operation is made. The write operation will write the messages through the * {@link ChannelPipeline}. Those are then ready to be flushed to the actual {@link Channel} once - * {@link Channel#flush()} is called + * {@link Channel#flush()} is called. * * @param ctx the {@link ChannelHandlerContext} for which the write operation is made * @param msg the message to write * @param promise the {@link ChannelPromise} to notify once the operation completes - * @throws Exception thrown if an error occurs */ @Skip - default void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + default void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { ctx.write(msg, promise); } @@ -377,10 +370,9 @@ public interface ChannelHandler { * that are pending. * * @param ctx the {@link ChannelHandlerContext} for which the flush operation is made - * @throws Exception thrown if an error occurs */ @Skip - default void flush(ChannelHandlerContext ctx) throws Exception { + default void flush(ChannelHandlerContext ctx) { ctx.flush(); } } diff --git a/transport/src/main/java/io/netty/channel/CombinedChannelDuplexHandler.java b/transport/src/main/java/io/netty/channel/CombinedChannelDuplexHandler.java index c7b65a3581..d01feb7706 100644 --- a/transport/src/main/java/io/netty/channel/CombinedChannelDuplexHandler.java +++ b/transport/src/main/java/io/netty/channel/CombinedChannelDuplexHandler.java @@ -243,7 +243,7 @@ public class CombinedChannelDuplexHandler outboundBuffer = new ArrayDeque<>(); @Override - public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { outboundBuffer.add(msg); } diff --git a/transport/src/test/java/io/netty/channel/LoggingHandler.java b/transport/src/test/java/io/netty/channel/LoggingHandler.java index 05990bf59f..6ed4ca753b 100644 --- a/transport/src/test/java/io/netty/channel/LoggingHandler.java +++ b/transport/src/test/java/io/netty/channel/LoggingHandler.java @@ -30,51 +30,50 @@ final class LoggingHandler implements ChannelHandler { private final EnumSet interest = EnumSet.allOf(Event.class); @Override - public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { log(Event.WRITE); ctx.write(msg, promise); } @Override - public void flush(ChannelHandlerContext ctx) throws Exception { + public void flush(ChannelHandlerContext ctx) { log(Event.FLUSH); ctx.flush(); } @Override - public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) - throws Exception { + public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) { log(Event.BIND, "localAddress=" + localAddress); ctx.bind(localAddress, promise); } @Override public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, - ChannelPromise promise) throws Exception { + ChannelPromise promise) { log(Event.CONNECT, "remoteAddress=" + remoteAddress + " localAddress=" + localAddress); ctx.connect(remoteAddress, localAddress, promise); } @Override - public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { + public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) { log(Event.DISCONNECT); ctx.disconnect(promise); } @Override - public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { + public void close(ChannelHandlerContext ctx, ChannelPromise promise) { log(Event.CLOSE); ctx.close(promise); } @Override - public void register(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { + public void register(ChannelHandlerContext ctx, ChannelPromise promise) { log(Event.REGISTER); ctx.register(promise); } @Override - public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { + public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) { log(Event.DEREGISTER); ctx.deregister(promise); } diff --git a/transport/src/test/java/io/netty/channel/PendingWriteQueueTest.java b/transport/src/test/java/io/netty/channel/PendingWriteQueueTest.java index 815e90f9b4..b42572053a 100644 --- a/transport/src/test/java/io/netty/channel/PendingWriteQueueTest.java +++ b/transport/src/test/java/io/netty/channel/PendingWriteQueueTest.java @@ -44,7 +44,7 @@ public class PendingWriteQueueTest { public void testRemoveAndWrite() { assertWrite(new TestHandler() { @Override - public void flush(ChannelHandlerContext ctx) throws Exception { + public void flush(ChannelHandlerContext ctx) { assertFalse(ctx.channel().isWritable(), "Should not be writable anymore"); ChannelFuture future = queue.removeAndWrite(); @@ -58,7 +58,7 @@ public class PendingWriteQueueTest { public void testRemoveAndWriteAll() { assertWrite(new TestHandler() { @Override - public void flush(ChannelHandlerContext ctx) throws Exception { + public void flush(ChannelHandlerContext ctx) { assertFalse(ctx.channel().isWritable(), "Should not be writable anymore"); ChannelFuture future = queue.removeAndWriteAll(); @@ -73,7 +73,7 @@ public class PendingWriteQueueTest { assertWriteFails(new TestHandler() { @Override - public void flush(ChannelHandlerContext ctx) throws Exception { + public void flush(ChannelHandlerContext ctx) { queue.removeAndFail(new TestException()); super.flush(ctx); } @@ -84,7 +84,7 @@ public class PendingWriteQueueTest { public void testRemoveAndFailAll() { assertWriteFails(new TestHandler() { @Override - public void flush(ChannelHandlerContext ctx) throws Exception { + public void flush(ChannelHandlerContext ctx) { queue.removeAndFailAll(new TestException()); super.flush(ctx); } @@ -358,7 +358,7 @@ public class PendingWriteQueueTest { } @Override - public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { queue.add(msg, promise); assertFalse(queue.isEmpty()); assertEquals(++expectedSize, queue.size()); diff --git a/transport/src/test/java/io/netty/channel/ReentrantChannelTest.java b/transport/src/test/java/io/netty/channel/ReentrantChannelTest.java index fdac3841cc..0720ec3642 100644 --- a/transport/src/test/java/io/netty/channel/ReentrantChannelTest.java +++ b/transport/src/test/java/io/netty/channel/ReentrantChannelTest.java @@ -173,7 +173,7 @@ public class ReentrantChannelTest extends BaseChannelTest { int flushCount; @Override - public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { if (writeCount < 5) { writeCount++; ctx.channel().flush(); @@ -182,7 +182,7 @@ public class ReentrantChannelTest extends BaseChannelTest { } @Override - public void flush(ChannelHandlerContext ctx) throws Exception { + public void flush(ChannelHandlerContext ctx) { if (flushCount < 5) { flushCount++; ctx.channel().write(createTestBuf(2000)); @@ -227,7 +227,7 @@ public class ReentrantChannelTest extends BaseChannelTest { clientChannel.pipeline().addLast(new ChannelHandler() { @Override - public void write(final ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + public void write(final ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { promise.addListener(future -> ctx.channel().close()); ctx.write(msg, promise); ctx.channel().flush(); @@ -257,14 +257,8 @@ public class ReentrantChannelTest extends BaseChannelTest { clientChannel.pipeline().addLast(new ChannelHandler() { @Override - public void flush(ChannelHandlerContext ctx) throws Exception { - throw new Exception("intentional failure"); - } - - }, new ChannelHandler() { - @Override - public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { - ctx.close(); + public void flush(ChannelHandlerContext ctx) { + throw new RuntimeException("intentional failure"); } }); diff --git a/transport/src/test/java/io/netty/channel/embedded/EmbeddedChannelTest.java b/transport/src/test/java/io/netty/channel/embedded/EmbeddedChannelTest.java index 6e525b32b0..8e644e6ae2 100644 --- a/transport/src/test/java/io/netty/channel/embedded/EmbeddedChannelTest.java +++ b/transport/src/test/java/io/netty/channel/embedded/EmbeddedChannelTest.java @@ -255,7 +255,7 @@ public class EmbeddedChannelTest { public void testHasNoDisconnectSkipDisconnect() throws InterruptedException { EmbeddedChannel channel = new EmbeddedChannel(false, new ChannelHandler() { @Override - public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { + public void close(ChannelHandlerContext ctx, ChannelPromise promise) { promise.tryFailure(new Throwable()); } }); @@ -347,8 +347,7 @@ public class EmbeddedChannelTest { public void testWriteLater() { EmbeddedChannel channel = new EmbeddedChannel(new ChannelHandler() { @Override - public void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) - throws Exception { + public void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) { ctx.executor().execute(() -> ctx.write(msg, promise)); } }); @@ -365,8 +364,7 @@ public class EmbeddedChannelTest { final int delay = 500; EmbeddedChannel channel = new EmbeddedChannel(new ChannelHandler() { @Override - public void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) - throws Exception { + public void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) { ctx.executor().schedule(() -> { ctx.writeAndFlush(msg, promise); }, delay, TimeUnit.MILLISECONDS); @@ -434,7 +432,7 @@ public class EmbeddedChannelTest { final CountDownLatch latch = new CountDownLatch(1); EmbeddedChannel channel = new EmbeddedChannel(new ChannelHandler() { @Override - public void flush(ChannelHandlerContext ctx) throws Exception { + public void flush(ChannelHandlerContext ctx) { latch.countDown(); } }); @@ -453,13 +451,13 @@ public class EmbeddedChannelTest { EmbeddedChannel channel = new EmbeddedChannel(new ChannelHandler() { @Override - public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { ctx.write(msg, promise); latch.countDown(); } @Override - public void flush(ChannelHandlerContext ctx) throws Exception { + public void flush(ChannelHandlerContext ctx) { flushCount.incrementAndGet(); } }); @@ -572,13 +570,13 @@ public class EmbeddedChannelTest { private final Queue queue = new ArrayDeque<>(); @Override - public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { + public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) { queue.add(DISCONNECT); promise.setSuccess(); } @Override - public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { + public void close(ChannelHandlerContext ctx, ChannelPromise promise) { queue.add(CLOSE); promise.setSuccess(); }