From a65f097d53f8d1827556d4d1b41d8432d3c664b5 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Tue, 8 Oct 2013 17:18:41 +0900 Subject: [PATCH] Allow empty handler list when creating a new EmbeddedChannel .. so that it can be used for dynamically initialized pipelines - Fixes #1899 --- .../channel/embedded/EmbeddedChannel.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/transport/src/main/java/io/netty/channel/embedded/EmbeddedChannel.java b/transport/src/main/java/io/netty/channel/embedded/EmbeddedChannel.java index 31e26f54ae..ccbfa49160 100644 --- a/transport/src/main/java/io/netty/channel/embedded/EmbeddedChannel.java +++ b/transport/src/main/java/io/netty/channel/embedded/EmbeddedChannel.java @@ -44,7 +44,8 @@ import java.util.Queue; */ public class EmbeddedChannel extends AbstractChannel { - private enum State { OPEN, ACTIVE, CLOSED }; + private static final ChannelHandler[] EMPTY_HANDLERS = new ChannelHandler[0]; + private enum State { OPEN, ACTIVE, CLOSED } private static final InternalLogger logger = InternalLoggerFactory.getInstance(EmbeddedChannel.class); @@ -60,7 +61,14 @@ public class EmbeddedChannel extends AbstractChannel { private State state; /** - * Create a new instance + * Create a new instance with an empty pipeline. + */ + public EmbeddedChannel() { + this(EMPTY_HANDLERS); + } + + /** + * Create a new instance with the pipeline initialized with the specified handlers. * * @param handlers the @link ChannelHandler}s which will be add in the {@link ChannelPipeline} */ @@ -71,20 +79,14 @@ public class EmbeddedChannel extends AbstractChannel { throw new NullPointerException("handlers"); } - int nHandlers = 0; ChannelPipeline p = pipeline(); for (ChannelHandler h: handlers) { if (h == null) { break; } - nHandlers ++; p.addLast(h); } - if (nHandlers == 0) { - throw new IllegalArgumentException("handlers is empty."); - } - p.addLast(new LastInboundHandler()); loop.register(this); }