DefaultChannelPipeline implements ChannelPipeline { @Override public ChannelHandler get(String name) { ChannelHandlerContext ctx = context(name); if (ctx == null) { return null; } else { return ctx.handler(); } } DefaultChannelPipeline(AbstractChannel channel); @Override Channel channel(); @Override ChannelPipeline addFirst(String name, ChannelHandler handler); @Override synchronized ChannelPipeline addFirst(EventExecutorGroup group, String name, ChannelHandler handler); @Override ChannelPipeline addFirst(ChannelHandlerInvoker invoker, String name, ChannelHandler handler); @Override ChannelPipeline addLast(String name, ChannelHandler handler); @Override synchronized ChannelPipeline addLast(EventExecutorGroup group, String name, ChannelHandler handler); @Override synchronized ChannelPipeline addLast(ChannelHandlerInvoker invoker, String name, ChannelHandler handler); @Override ChannelPipeline addBefore(String baseName, String name, ChannelHandler handler); @Override synchronized ChannelPipeline addBefore(
            EventExecutorGroup group, String baseName, String name, ChannelHandler handler); @Override synchronized ChannelPipeline addBefore(
            ChannelHandlerInvoker invoker, String baseName, String name, ChannelHandler handler); @Override ChannelPipeline addAfter(String baseName, String name, ChannelHandler handler); @Override synchronized ChannelPipeline addAfter(
            EventExecutorGroup group, String baseName, String name, ChannelHandler handler); @Override synchronized ChannelPipeline addAfter(
            ChannelHandlerInvoker invoker, String baseName, String name, ChannelHandler handler); @Override ChannelPipeline addFirst(ChannelHandler... handlers); @Override ChannelPipeline addFirst(EventExecutorGroup group, ChannelHandler... handlers); @Override ChannelPipeline addFirst(ChannelHandlerInvoker invoker, ChannelHandler... handlers); @Override ChannelPipeline addLast(ChannelHandler... handlers); @Override ChannelPipeline addLast(EventExecutorGroup group, ChannelHandler... handlers); @Override ChannelPipeline addLast(ChannelHandlerInvoker invoker, ChannelHandler... handlers); @Override ChannelPipeline remove(ChannelHandler handler); @Override ChannelHandler remove(String name); @SuppressWarnings("unchecked") @Override T remove(Class<T> handlerType); @Override ChannelHandler removeFirst(); @Override ChannelHandler removeLast(); @Override ChannelPipeline replace(ChannelHandler oldHandler, String newName, ChannelHandler newHandler); @Override ChannelHandler replace(String oldName, String newName, ChannelHandler newHandler); @Override @SuppressWarnings("unchecked") T replace(
            Class<T> oldHandlerType, String newName, ChannelHandler newHandler); @Override ChannelHandler first(); @Override ChannelHandlerContext firstContext(); @Override ChannelHandler last(); @Override ChannelHandlerContext lastContext(); @Override ChannelHandler get(String name); @SuppressWarnings("unchecked") @Override T get(Class<T> handlerType); @Override ChannelHandlerContext context(String name); @Override ChannelHandlerContext context(ChannelHandler handler); @Override ChannelHandlerContext context(Class<? extends ChannelHandler> handlerType); @Override List<String> names(); @Override Map<String, ChannelHandler> toMap(); @Override Iterator<Map.Entry<String, ChannelHandler>> iterator(); @Override String toString(); @Override ChannelPipeline fireChannelRegistered(); @Override ChannelPipeline fireChannelUnregistered(); @Override ChannelPipeline fireChannelActive(); @Override ChannelPipeline fireChannelInactive(); @Override ChannelPipeline fireExceptionCaught(Throwable cause); @Override ChannelPipeline fireUserEventTriggered(Object event); @Override ChannelPipeline fireChannelRead(Object msg); @Override ChannelPipeline fireChannelReadComplete(); @Override ChannelPipeline fireChannelWritabilityChanged(); @Override ChannelFuture bind(SocketAddress localAddress); @Override ChannelFuture connect(SocketAddress remoteAddress); @Override ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress); @Override ChannelFuture disconnect(); @Override ChannelFuture close(); @Override ChannelFuture deregister(); @Override ChannelPipeline flush(); @Override ChannelFuture bind(SocketAddress localAddress, ChannelPromise promise); @Override ChannelFuture connect(SocketAddress remoteAddress, ChannelPromise promise); @Override ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise); @Override ChannelFuture disconnect(ChannelPromise promise); @Override ChannelFuture close(ChannelPromise promise); @Override ChannelFuture deregister(ChannelPromise promise); @Override ChannelPipeline read(); @Override ChannelFuture write(Object msg); @Override ChannelFuture write(Object msg, ChannelPromise promise); @Override ChannelFuture writeAndFlush(Object msg, ChannelPromise promise); @Override ChannelFuture writeAndFlush(Object msg);  }
@Test(timeout = 5000) public void testChannelInitializerException() throws Exception { final IllegalStateException exception = new IllegalStateException(); final AtomicReference<Throwable> error = new AtomicReference<Throwable>(); final CountDownLatch latch = new CountDownLatch(1); EmbeddedChannel channel = new EmbeddedChannel(new ChannelInitializer<Channel>() { @Override protected void initChannel(Channel ch) throws Exception { throw exception; } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { super.exceptionCaught(ctx, cause); error.set(cause); latch.countDown(); } }); latch.await(); assertFalse(channel.isActive()); assertSame(exception, error.get()); }