From ccfbf9f346af16ad3cff6d01847a9cbc6e82ca77 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Fri, 24 Nov 2023 12:14:59 +0100 Subject: [PATCH 1/4] [caps] Use a synchronous listener for incoming presence stanzas Fixes SMACK-937. --- .../java/org/jivesoftware/smackx/caps/EntityCapsManager.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java index ff3eb0c47..9b736f6d4 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java @@ -354,7 +354,10 @@ public final class EntityCapsManager extends Manager { if (autoEnableEntityCaps) enableEntityCaps(); - connection.addAsyncStanzaListener(new StanzaListener() { + // Note that this is a *synchronous* stanza listener to avoid unnecessary feature lookups. If this were to be an + // asynchronous listener, then it would be possible that the entity caps information was not processed when the + // features of entity are looked up. See SMACK-937. + connection.addStanzaListener(new StanzaListener() { // Listen for remote presence stanzas with the caps extension // If we receive such a stanza, record the JID and nodeVer @Override From f593b6d0a02fac407193d50e3f9b2a33380ed437 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Fri, 24 Nov 2023 12:18:19 +0100 Subject: [PATCH 2/4] [core] Whitespace fix in XMPPConnection's javadoc --- .../src/main/java/org/jivesoftware/smack/XMPPConnection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java index 1d3ca49d1..17395c334 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java @@ -370,7 +370,7 @@ public interface XMPPConnection { boolean removeStanzaListener(StanzaListener stanzaListener); /** - * Registers a synchronous stanza listener with this connection. A stanza listener will be invoked only when + * Registers a synchronous stanza listener with this connection. A stanza listener will be invoked only when * an incoming stanza is received. A stanza filter determines which stanzas will be delivered to the listener. If * the same stanza listener is added again with a different filter, only the new filter will be used. *

From a270542397d591fff02e4a54d74dd0bc36874b5b Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Fri, 24 Nov 2023 12:59:04 +0100 Subject: [PATCH 3/4] [core] Improve javadoc for listeners With 92f253cc74a4 ("[core] Replace AbstractXMPPConnection.inOrderListeners") we changes the behavior of listeners. This commit documents the expectations to the user. --- .../jivesoftware/smack/XMPPConnection.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java index 17395c334..ffc211b84 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java @@ -83,23 +83,24 @@ import org.jxmpp.jid.EntityFullJid; *

Incoming Stanza Listeners

* Most callbacks (listeners, handlers, …) than you can add to a connection come in three different variants: * *

- * Standard callbacks are invoked concurrently, but it is ensured that the same callback is never run concurrently. - * The callback's identity is used as key for that. The events delivered to the callback preserve the order of the - * causing events of the connection. - *

- *

* Asynchronous callbacks are run decoupled from the connections main event loop. Hence a callback triggered by * stanza B may (appear to) invoked before a callback triggered by stanza A, even though stanza A arrived before B. *

*

- * Synchronous callbacks are run synchronous to the main event loop of a connection. Hence they are invoked in the - * exact order of how events happen there, most importantly the arrival order of incoming stanzas. You should only - * use synchronous callbacks in rare situations. + * Synchronous callbacks are invoked concurrently, but it is ensured that the same callback is never run concurrently + * and that they are executed in order. That is, if both stanza A and B trigger the same callback, and A arrives before + * B, then the callback will be invoked with A first, and then B. Furthermore, those callbacks are not executed within + * the main loop. However it is still advisable that those callbacks do not block or only block briefly. + *

+ *

+ * Other callbacks are run synchronous to the main event loop of a connection and are executed within the main loop. + * This means that if such a callback blocks, the main event loop also blocks, which can easily cause deadlocks. + * Therefore, you should avoid using those callbacks unless you know what you are doing. *

* * @author Matt Tucker From 5560fb4752b19d79455b9b7179498f3279b7901d Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Fri, 24 Nov 2023 13:09:21 +0100 Subject: [PATCH 4/4] [chatmarkers] Deprecate ChatMarkers.isSupportedByServer() Fixes SMACK-934. --- .../jivesoftware/smackx/chat_markers/ChatMarkersManager.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/ChatMarkersManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/ChatMarkersManager.java index b2f99bd76..60b125742 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/ChatMarkersManager.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/ChatMarkersManager.java @@ -174,7 +174,10 @@ public final class ChatMarkersManager extends Manager { * @throws XMPPErrorException in case an error response was received. * @throws NoResponseException if no response was received. * @throws InterruptedException if the connection is interrupted. + * @deprecated This method serves no purpose, as servers do not announce this feature. */ + // TODO: Remove in Smack 4.6. + @Deprecated public boolean isSupportedByServer() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { return ServiceDiscoveryManager.getInstanceFor(connection())