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 76d8271ec7..4f641a5559 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
@@ -165,14 +165,15 @@ protected void connectInternal() throws SmackException, InterruptedException {
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)
@@ -295,10 +296,11 @@ public void instantShutdown() {
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;
}
/**
@@ -376,6 +378,8 @@ public void requestSent(BOSHMessageEvent event) {
if (event.getBody() != null) {
try {
writer.write(event.getBody().toXML());
+ // Fix all BOSH sent debug messages not shown
+ writer.flush();
} catch (Exception e) {
// Ignore
}