From 02703e8fc1cf1560fccc7ebd804b274d24acb1b3 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Sat, 7 Dec 2013 10:57:13 +0900 Subject: [PATCH] Revert "Fix NoSuchElementException raised by ChannelInitializer" This reverts commit 3c453f5dbaf8524d46c9fb3285d2ea7ae8bdb5b6. --- .../main/java/io/netty/channel/ChannelInitializer.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/transport/src/main/java/io/netty/channel/ChannelInitializer.java b/transport/src/main/java/io/netty/channel/ChannelInitializer.java index 5790ad8b41..043458b554 100644 --- a/transport/src/main/java/io/netty/channel/ChannelInitializer.java +++ b/transport/src/main/java/io/netty/channel/ChannelInitializer.java @@ -60,19 +60,22 @@ public abstract class ChannelInitializer extends ChannelInbou */ protected abstract void initChannel(C ch) throws Exception; - @Override @SuppressWarnings("unchecked") - public final void channelRegistered(ChannelHandlerContext ctx) throws Exception { + @Override + public final void channelRegistered(ChannelHandlerContext ctx) + throws Exception { + boolean removed = false; boolean success = false; try { initChannel((C) ctx.channel()); ctx.pipeline().remove(this); + removed = true; ctx.fireChannelRegistered(); success = true; } catch (Throwable t) { logger.warn("Failed to initialize a channel. Closing: " + ctx.channel(), t); } finally { - if (!ctx.isRemoved()) { + if (!removed) { ctx.pipeline().remove(this); } if (!success) {