mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 14:22:05 +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
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void login() throws XMPPException, SmackException, IOException {
|
public void login() throws XMPPException, SmackException, IOException {
|
||||||
|
if (isAnonymous()) {
|
||||||
throwNotConnectedExceptionIfAppropriate();
|
throwNotConnectedExceptionIfAppropriate();
|
||||||
throwAlreadyLoggedInExceptionIfAppropriate();
|
throwAlreadyLoggedInExceptionIfAppropriate();
|
||||||
if (isAnonymous()) {
|
|
||||||
loginAnonymously();
|
loginAnonymously();
|
||||||
} else {
|
} else {
|
||||||
// The previously used username, password and resource take over precedence over the
|
// 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)) {
|
if (!config.allowNullOrEmptyUsername && StringUtils.isNullOrEmpty(username)) {
|
||||||
throw new IllegalArgumentException("Username must not be null or empty");
|
throw new IllegalArgumentException("Username must not be null or empty");
|
||||||
}
|
}
|
||||||
|
throwNotConnectedExceptionIfAppropriate();
|
||||||
|
throwAlreadyLoggedInExceptionIfAppropriate();
|
||||||
usedUsername = username;
|
usedUsername = username;
|
||||||
usedPassword = password;
|
usedPassword = password;
|
||||||
usedResource = resource;
|
usedResource = resource;
|
||||||
|
|
|
@ -306,6 +306,9 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void throwNotConnectedExceptionIfAppropriate() throws NotConnectedException {
|
protected void throwNotConnectedExceptionIfAppropriate() throws NotConnectedException {
|
||||||
|
if (packetWriter == null) {
|
||||||
|
throw new NotConnectedException();
|
||||||
|
}
|
||||||
packetWriter.throwNotConnectedExceptionIfDoneAndResumptionNotPossible();
|
packetWriter.throwNotConnectedExceptionIfDoneAndResumptionNotPossible();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue