Fix NPE which is triggered if the destory method is called before

channelOpen(..). See #143
This commit is contained in:
Norman Maurer 2012-01-07 17:44:36 +01:00
parent 72a8159344
commit 54bba7239c

View File

@ -304,6 +304,12 @@ public class IdleStateHandler extends SimpleChannelUpstreamHandler
private void destroy(ChannelHandlerContext ctx) { private void destroy(ChannelHandlerContext ctx) {
State state = (State) ctx.getAttachment(); State state = (State) ctx.getAttachment();
// Check if the state was set before, it may not if the destroy method was called before the
// channelOpen(...) method.
//
// See #143
if (state != null) {
if (state.readerIdleTimeout != null) { if (state.readerIdleTimeout != null) {
state.readerIdleTimeout.cancel(); state.readerIdleTimeout.cancel();
state.readerIdleTimeout = null; state.readerIdleTimeout = null;
@ -318,6 +324,8 @@ public class IdleStateHandler extends SimpleChannelUpstreamHandler
} }
} }
}
protected void channelIdle( protected void channelIdle(
ChannelHandlerContext ctx, IdleState state, long lastActivityTimeMillis) throws Exception { ChannelHandlerContext ctx, IdleState state, long lastActivityTimeMillis) throws Exception {
ctx.sendUpstream(new DefaultIdleStateEvent(ctx.getChannel(), state, lastActivityTimeMillis)); ctx.sendUpstream(new DefaultIdleStateEvent(ctx.getChannel(), state, lastActivityTimeMillis));