The problem: when connection is resumed we want to join MUC again. We call MultiUserChat.join which inside calls leave(). leave() does not wait for result, it’s essentially an async call. Immediately after leave enter(…) is called and it waits for next result. However it gets result of leave and continues. Does not wait for proper MUC join result and this triggers errors if MUC message is sent immediately after join.
The code for join:
public synchronized void join(MucEnterConfiguration mucEnterConfiguration)
throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException, NotAMucServiceException {
// If we've already joined the room, leave it before joining under a new
// nickname.
if (joined) {
leave();
}
enter(mucEnterConfiguration);
}
Proposed solution: make MultiUserChat.leave() a synchronized call. E.g.
public synchronized void leave() throws NotConnectedException, InterruptedException {
...
connection.sendStanza(leavePresence).nextResultOrThrow(conf.getTimeout());
}