From ba5f34e2de8376e7650004d771f38b999ca76652 Mon Sep 17 00:00:00 2001 From: Yaroslav Saakyan Date: Tue, 25 Dec 2018 13:33:29 +0300 Subject: [PATCH] #136 - Add null checks for NettyWebSocket#channel. Revert "#136 - Remove setting channel to null in NettyWebSocket#recycle()." This reverts commit 73c8792a5240f0995c31a6071a39fbe45d8b7994. --- .../java/org/atmosphere/nettosphere/NettyWebSocket.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/atmosphere/nettosphere/NettyWebSocket.java b/server/src/main/java/org/atmosphere/nettosphere/NettyWebSocket.java index ce9cbfa..7349e12 100644 --- a/server/src/main/java/org/atmosphere/nettosphere/NettyWebSocket.java +++ b/server/src/main/java/org/atmosphere/nettosphere/NettyWebSocket.java @@ -83,7 +83,7 @@ public WebSocket resource(AtmosphereResource r) { @Override public WebSocket write(String data) throws IOException { firstWrite.set(true); - if (!channel.isOpen()) throw REMOTELY_CLOSED; + if (channel == null || !channel.isOpen()) throw REMOTELY_CLOSED; if (binaryWrite) { channel.write(new BinaryWebSocketFrame(ChannelBuffers.wrappedBuffer(data.getBytes("UTF-8")))); @@ -111,7 +111,7 @@ public WebSocket write(byte[] data, int offset, int length) throws IOException { void _write(byte[] data, int offset, int length) throws IOException { firstWrite.set(true); - if (!channel.isOpen()) throw REMOTELY_CLOSED; + if (channel == null || !channel.isOpen()) throw REMOTELY_CLOSED; if (binaryWrite) { channel.write(new BinaryWebSocketFrame(ChannelBuffers.wrappedBuffer(data, offset, length))); @@ -123,6 +123,9 @@ void _write(byte[] data, int offset, int length) throws IOException { @Override public boolean isOpen() { + if (channel == null) { + return false; + } return channel.isOpen(); } @@ -146,6 +149,7 @@ public void close() { public void recycle() { if (headers != null) headers.clear(); + channel = null; } /**