diff --git a/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java index 14d7c0e90..f1c0b9015 100644 --- a/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java +++ b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java @@ -172,14 +172,15 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection { client = BOSHClient.create(cfgBuilder.build()); - client.addBOSHClientConnListener(new BOSHConnectionListener()); - client.addBOSHClientResponseListener(new BOSHPacketReader()); - - // Initialize the debugger + // Initialize the debugger before addBOSHClientResponseListener(new BOSHPacketReader()); + // BOSHPacketReader may hold and send response prior to display of the request i.e. before if (debugger != null) { initDebugger(); } + client.addBOSHClientConnListener(new BOSHConnectionListener()); + client.addBOSHClientResponseListener(new BOSHPacketReader()); + // Send the session creation request client.send(ComposableBody.builder() .setNamespaceDefinition("xmpp", XMPP_BOSH_NS) @@ -359,10 +360,11 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection { CloseableUtil.maybeClose(reader, LOGGER); CloseableUtil.maybeClose(writer, LOGGER); + // set readerConsumer = null before reader to avoid NPE reference + readerConsumer = null; readerPipe = null; reader = null; writer = null; - readerConsumer = null; } /** @@ -440,6 +442,8 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection { if (event.getBody() != null) { try { writer.write(event.getBody().toXML()); + // Fix all BOSH sent debug messages not shown + writer.flush(); } catch (Exception e) { // Ignore }