1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-12-22 18:48:00 +01:00

[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>
This commit is contained in:
Florian Schmaus 2022-02-02 12:44:04 +01:00
parent 4cdb4acf26
commit 3ff553549a

View file

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