From f7cc2c971dc0a7530c9319d6df24da4d8550a7d9 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Mon, 9 Feb 2009 09:06:39 +0000 Subject: [PATCH] Fixed NPE in LocalChannel.closeNow() --- .../netty/channel/local/LocalChannel.java | 53 +++++++++++-------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/jboss/netty/channel/local/LocalChannel.java b/src/main/java/org/jboss/netty/channel/local/LocalChannel.java index f2965bb09d..712b9fb52d 100644 --- a/src/main/java/org/jboss/netty/channel/local/LocalChannel.java +++ b/src/main/java/org/jboss/netty/channel/local/LocalChannel.java @@ -109,7 +109,7 @@ class LocalChannel extends AbstractChannel { fireChannelClosed(this); // Close the peer. - if (!pairedChannel.setClosed()) { + if (pairedChannel == null || !pairedChannel.setClosed()) { return; } @@ -130,26 +130,9 @@ class LocalChannel extends AbstractChannel { void flushWriteBuffer() { LocalChannel pairedChannel = this.pairedChannel; - if (pairedChannel == null || !pairedChannel.isConnected()) { - // Channel is closed or not connected yet - notify as failures. - Exception cause; - if (isOpen()) { - cause = new NotYetConnectedException(); - } else { - cause = new ClosedChannelException(); - } - - for (;;) { - MessageEvent e = writeBuffer.poll(); - if(e == null) { - break; - } - - e.getFuture().setFailure(cause); - fireExceptionCaught(this, cause); - } - } else { - // Channel is open and connected - trigger events. + if (isConnected()){ + // Channel is open and connected and channelConnected event has + // been fired. if (!delivering.get()) { delivering.set(true); try { @@ -167,6 +150,34 @@ class LocalChannel extends AbstractChannel { delivering.set(false); } } + + return; + } + + if (pairedChannel != null) { + // Channel is open and connected but channelConnected event has + // not been fired yet. + return; + } + + if (pairedChannel == null || !isOpen()) { + // Channel is closed or not connected yet - notify as failures. + Exception cause; + if (isOpen()) { + cause = new NotYetConnectedException(); + } else { + cause = new ClosedChannelException(); + } + + for (;;) { + MessageEvent e = writeBuffer.poll(); + if(e == null) { + break; + } + + e.getFuture().setFailure(cause); + fireExceptionCaught(this, cause); + } } } }