mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-22 02:27:58 +01:00
Throw NotConnectedException on login()
if connect() was not previously called. Previously calling login() with arguments would not check for the preconditions. The check to throw needs to be performed in AbstractXMPPConnection before every 'abstract login(Non)Anonymously()' call. That's the two lines that check the preconditions are duplicated. Also fix NPE in XMPPTCPConnection.throwNotConnectedExceptionIfAppropriate() when packetWrite is null (i.e. if the connection was never connected before).
This commit is contained in:
parent
75fd1683d1
commit
6d7f3904d9
2 changed files with 7 additions and 2 deletions
|
@ -393,9 +393,9 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
* @throws IOException
|
||||
*/
|
||||
public void login() throws XMPPException, SmackException, IOException {
|
||||
throwNotConnectedExceptionIfAppropriate();
|
||||
throwAlreadyLoggedInExceptionIfAppropriate();
|
||||
if (isAnonymous()) {
|
||||
throwNotConnectedExceptionIfAppropriate();
|
||||
throwAlreadyLoggedInExceptionIfAppropriate();
|
||||
loginAnonymously();
|
||||
} else {
|
||||
// The previously used username, password and resource take over precedence over the
|
||||
|
@ -440,6 +440,8 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
if (!config.allowNullOrEmptyUsername && StringUtils.isNullOrEmpty(username)) {
|
||||
throw new IllegalArgumentException("Username must not be null or empty");
|
||||
}
|
||||
throwNotConnectedExceptionIfAppropriate();
|
||||
throwAlreadyLoggedInExceptionIfAppropriate();
|
||||
usedUsername = username;
|
||||
usedPassword = password;
|
||||
usedResource = resource;
|
||||
|
|
|
@ -306,6 +306,9 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
|||
|
||||
@Override
|
||||
protected void throwNotConnectedExceptionIfAppropriate() throws NotConnectedException {
|
||||
if (packetWriter == null) {
|
||||
throw new NotConnectedException();
|
||||
}
|
||||
packetWriter.throwNotConnectedExceptionIfDoneAndResumptionNotPossible();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue