1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-09-10 18:59:41 +02:00

"not connected" is now a checked Exception thrown by sendPacket()

There is a unsolveable race condition between the connection state and
sendPacket(), i.e. the connection could go down, right after the
method calling sendPacket is called, but before sendPacket() is
invoked. Before this change, sendPacket() has thrown an unchecked
IllegalStateException, which could be ignored by the Smack user, who
would also not notice the race condition. We have decided to throw a
checked Exception in this case now, to make the Smack user aware of
this situation.

SMACK-426
This commit is contained in:
Florian Schmaus 2014-03-19 14:22:20 +01:00
parent d8c656270e
commit fcc8414a92
101 changed files with 845 additions and 382 deletions

View file

@ -20,6 +20,7 @@ package org.jivesoftware.smackx.debugger;
import org.jivesoftware.smack.AbstractConnectionListener;
import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.debugger.SmackDebugger;
import org.jivesoftware.smack.packet.IQ;
@ -36,6 +37,7 @@ import javax.swing.text.BadLocationException;
import javax.xml.transform.*;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
@ -545,7 +547,12 @@ public class EnhancedDebugger implements SmackDebugger {
public void actionPerformed(ActionEvent e) {
if (!"".equals(adhocMessages.getText())) {
AdHocPacket packetToSend = new AdHocPacket(adhocMessages.getText());
connection.sendPacket(packetToSend);
try {
connection.sendPacket(packetToSend);
}
catch (NotConnectedException e1) {
e1.printStackTrace();
}
}
}
});