From 78dcaec75bbd26f795e37776d3d8b8748a03226f Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sat, 9 Feb 2019 18:20:55 +0100 Subject: [PATCH] Remove null checks for writer/reader fields in XMPPTCPConnection as those are never null since 60f324eb1b8db2b910cc952ef6accdad22d45afc (the previous commit). --- .../smack/SynchronizationPoint.java | 10 +++++++ .../smack/tcp/XMPPTCPConnection.java | 26 ++++++++----------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/SynchronizationPoint.java b/smack-core/src/main/java/org/jivesoftware/smack/SynchronizationPoint.java index a7113b284..a40c3aeb5 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/SynchronizationPoint.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/SynchronizationPoint.java @@ -234,6 +234,16 @@ public class SynchronizationPoint { } } + public boolean isNotInInitialState() { + connectionLock.lock(); + try { + return state != State.Initial; + } + finally { + connectionLock.unlock(); + } + } + /** * Check if this synchronization point has its request already sent. * diff --git a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java index af7ffdeeb..8b1bdb70f 100644 --- a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java +++ b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java @@ -492,10 +492,8 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { // First shutdown the writer, this will result in a closing stream element getting send to // the server - if (packetWriter != null) { - LOGGER.finer("PacketWriter shutdown()"); - packetWriter.shutdown(instant); - } + LOGGER.finer("PacketWriter shutdown()"); + packetWriter.shutdown(instant); LOGGER.finer("PacketWriter has been shut down"); if (!instant) { @@ -510,10 +508,8 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { } } - if (packetReader != null) { - LOGGER.finer("PacketReader shutdown()"); - packetReader.shutdown(); - } + LOGGER.finer("PacketReader shutdown()"); + packetReader.shutdown(); LOGGER.finer("PacketReader has been shut down"); try { @@ -929,8 +925,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { */ private synchronized void notifyConnectionError(Exception e) { // Listeners were already notified of the exception, return right here. - if ((packetReader == null || packetReader.done) && - (packetWriter == null || packetWriter.done())) return; + if (packetReader.done && packetWriter.done()) return; SmackWrappedException smackWrappedException = new SmackWrappedException(e); tlsHandled.reportGenericFailure(smackWrappedException); @@ -1386,11 +1381,12 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { instantShutdown = instant; queue.shutdown(); shutdownTimestamp = System.currentTimeMillis(); - try { - shutdownDone.checkIfSuccessOrWait(); - } - catch (NoResponseException | InterruptedException e) { - LOGGER.log(Level.WARNING, "shutdownDone was not marked as successful by the writer thread", e); + if (shutdownDone.isNotInInitialState()) { + try { + shutdownDone.checkIfSuccessOrWait(); + } catch (NoResponseException | InterruptedException e) { + LOGGER.log(Level.WARNING, "shutdownDone was not marked as successful by the writer thread", e); + } } }