[SmackFuture] Invoke the callbacks at most once

Previously, if a SmackFuture both was successful and unsuccessful, it
was possible that the onSuccess() callback was invoked twice.

Reported-by: Boris Grozev <boris@jitsi.org>
master
Florian Schmaus 8 months ago
parent 4cdb4acf26
commit 3ff553549a
  1. 7
      smack-core/src/main/java/org/jivesoftware/smack/SmackFuture.java

@ -162,16 +162,20 @@ public abstract class SmackFuture<V, E extends Exception> implements Future<V>,
return result;
}
private boolean callbacksInvoked;
protected final synchronized void maybeInvokeCallbacks() {
if (cancelled) {
if (cancelled || callbacksInvoked) {
return;
}
if ((result != null || exception != null) && completionCallback != null) {
callbacksInvoked = true;
completionCallback.accept(this);
}
if (result != null && successCallback != null) {
callbacksInvoked = true;
AbstractXMPPConnection.asyncGo(new Runnable() {
@Override
public void run() {
@ -180,6 +184,7 @@ public abstract class SmackFuture<V, E extends Exception> implements Future<V>,
});
}
else if (exception != null && exceptionCallback != null) {
callbacksInvoked = true;
AbstractXMPPConnection.asyncGo(new Runnable() {
@Override
public void run() {

Loading…
Cancel
Save