[core] Inline waitForConditionOrConnectionException

Using any of the two methods is error prone, see 0e0c0a4093 ("[tcp]
Fix handling in connection exceptions when resuming a stream"), as one
can easily forget to check for connection exceptions after it
returned. There are also no longer any call sites of those methods.

Let's inline both variants of this method.
This commit is contained in:
Florian Schmaus 2022-04-30 15:08:44 +02:00
parent 0e0c0a4093
commit 1f5326abb2
1 changed files with 9 additions and 13 deletions

View File

@ -691,7 +691,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
}
/**
* We use an extra object for {@link #notifyWaitingThreads()} and {@link #waitForConditionOrConnectionException(Supplier)}, because all state
* We use an extra object for {@link #notifyWaitingThreads()} and {@link #waitFor(Supplier)}, because all state
* changing methods of the connection are synchronized using the connection instance as monitor. If we now would
* also use the connection instance for the internal process to wait for a condition, the {@link Object#wait()}
* would leave the monitor when it waites, which would allow for another potential call to a state changing function
@ -719,22 +719,18 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
return true;
}
protected final boolean waitForConditionOrConnectionException(Supplier<Boolean> condition) throws InterruptedException {
return waitFor(() -> condition.get().booleanValue() || hasCurrentConnectionException());
}
protected final void waitForConditionOrConnectionException(Supplier<Boolean> condition, String waitFor) throws InterruptedException, NoResponseException {
boolean success = waitForConditionOrConnectionException(condition);
if (!success) {
throw NoResponseException.newWith(this, waitFor);
}
}
protected final void waitForConditionOrThrowConnectionException(Supplier<Boolean> condition, String waitFor) throws InterruptedException, SmackException, XMPPException {
waitForConditionOrConnectionException(condition, waitFor);
boolean success = waitFor(() -> condition.get().booleanValue() || hasCurrentConnectionException());
if (hasCurrentConnectionException()) {
throwCurrentConnectionException();
}
// If there was no connection exception and we still did not successfully wait for the condition to hold, then
// we ran into a no-response timeout.
if (!success) {
throw NoResponseException.newWith(this, waitFor);
}
// Otherwise we successfully awaited the condition.
}
protected Resourcepart bindResourceAndEstablishSession(Resourcepart resource)