diff options
author | Mohammad Arshad <arshad@apache.org> | 2022-04-08 22:08:55 +0530 |
---|---|---|
committer | Mate Szalay-Beko <mszalay@cloudera.com> | 2022-05-17 13:30:51 +0200 |
commit | d3fd534e278005f837bc921d78cbd00b56be1280 (patch) | |
tree | 52d341aee9cae32a7de624bc7e9fc8b22d9fa5e5 | |
parent | 071e93f9c940c5fd8be3269f32aeac674d4e508d (diff) | |
download | zookeeper-d3fd534e278005f837bc921d78cbd00b56be1280.tar.gz |
ZOOKEEPER-4514: ClientCnxnSocketNetty throwing NPE
Moved channel object null check to sendPkt method to cover all calling scenarios
Author: Mohammad Arshad <arshad@apache.org>
Reviewers: Mate Szalay-Beko <symat@apache.org>
Closes #1854 from arshadmohammad/ZOOKEEPER-4514-npe
(cherry picked from commit d5876e88d6bab3cc1cee04f996b9804ff21581cb)
Signed-off-by: Mohammad Arshad <arshad@apache.org>
(cherry picked from commit cb79fb97a8972250190cf9f4fc1937e137cadd53)
-rwxr-xr-x | zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxnSocketNetty.java | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxnSocketNetty.java b/zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxnSocketNetty.java index 2f000fc35..55c5a9125 100755 --- a/zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxnSocketNetty.java +++ b/zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxnSocketNetty.java @@ -310,7 +310,7 @@ public class ClientCnxnSocketNetty extends ClientCnxnSocket { * @return a ChannelFuture that will complete when the write operation * succeeds or fails. */ - private ChannelFuture sendPktAndFlush(Packet p) { + private ChannelFuture sendPktAndFlush(Packet p) throws IOException { return sendPkt(p, true); } @@ -320,7 +320,7 @@ public class ClientCnxnSocketNetty extends ClientCnxnSocket { * @return a ChannelFuture that will complete when the write operation * succeeds or fails. */ - private ChannelFuture sendPktOnly(Packet p) { + private ChannelFuture sendPktOnly(Packet p) throws IOException { return sendPkt(p, false); } @@ -331,7 +331,10 @@ public class ClientCnxnSocketNetty extends ClientCnxnSocket { } }; - private ChannelFuture sendPkt(Packet p, boolean doFlush) { + private ChannelFuture sendPkt(Packet p, boolean doFlush) throws IOException { + if (channel == null) { + throw new IOException("channel has been closed"); + } // Assuming the packet will be sent out successfully. Because if it fails, // the channel will close and clean up queues. p.createBB(); @@ -344,7 +347,7 @@ public class ClientCnxnSocketNetty extends ClientCnxnSocket { return result; } - private void sendPrimePacket() { + private void sendPrimePacket() throws IOException { // assuming the first packet is the priming packet. sendPktAndFlush(outgoingQueue.remove()); } @@ -352,7 +355,7 @@ public class ClientCnxnSocketNetty extends ClientCnxnSocket { /** * doWrite handles writing the packets from outgoingQueue via network to server. */ - private void doWrite(List<Packet> pendingQueue, Packet p, ClientCnxn cnxn) { + private void doWrite(List<Packet> pendingQueue, Packet p, ClientCnxn cnxn) throws IOException { updateNow(); boolean anyPacketsSent = false; while (true) { @@ -382,9 +385,6 @@ public class ClientCnxnSocketNetty extends ClientCnxnSocket { @Override void sendPacket(ClientCnxn.Packet p) throws IOException { - if (channel == null) { - throw new IOException("channel has been closed"); - } sendPktAndFlush(p); } |