Fixes two NullPointerExceptions in the presence and instant messaging OperationSets of Jabber privately reported by Yana Stamcheva.

cusax-fix
Lyubomir Marinov 16 years ago
parent 9b89700cd3
commit ca05515d76

@ -452,31 +452,22 @@ public void sendInstantMessage(Contact to, Message message)
/**
* Utility method throwing an exception if the stack is not properly
* initialized.
*
* @throws java.lang.IllegalStateException if the underlying stack is
* not registered and initialized.
*/
private void assertConnected() throws IllegalStateException
private void assertConnected()
throws IllegalStateException
{
if (jabberProvider == null)
throw new IllegalStateException(
"The provider must be non-null and signed on the "
+"service before being able to communicate.");
if (!jabberProvider.isRegistered())
if (opSetPersPresence == null)
{
// if we are not registered but the current status is online
// change the current status
if(opSetPersPresence.getPresenceStatus().isOnline())
{
opSetPersPresence.fireProviderStatusChangeEvent(
opSetPersPresence.getPresenceStatus(),
jabberProvider.getJabberStatusEnum().getStatus(
JabberStatusEnum.OFFLINE));
}
throw new IllegalStateException(
"The provider must be signed on the service before "
+"being able to communicate.");
throw
new IllegalStateException(
"The provider must be signed on the service before"
+ " being able to communicate.");
}
else
opSetPersPresence.assertConnected();
}
/**
@ -501,9 +492,10 @@ public void registrationStateChanged(RegistrationStateChangeEvent evt)
if (evt.getNewState() == RegistrationState.REGISTERING)
{
opSetPersPresence =
(OperationSetPersistentPresenceJabberImpl) jabberProvider
.getOperationSet(OperationSetPersistentPresence.class);
opSetPersPresence
= (OperationSetPersistentPresenceJabberImpl)
jabberProvider.getOperationSet(
OperationSetPersistentPresence.class);
if(smackMessageListener == null)
smackMessageListener = new SmackMessageListener();

@ -391,32 +391,53 @@ public void publishPresenceStatus(PresenceStatus status,
}
/**
* Get the PresenceStatus for a particular contact.
* Gets the <tt>PresenceStatus</tt> of a contact with a specific
* <tt>String</tt> identifier.
*
* @param contactIdentifier the identifier of the contact whose status
* we're interested in.
* @return PresenceStatus the <tt>PresenceStatus</tt> of the specified
* <tt>contact</tt>
* @throws IllegalArgumentException if <tt>contact</tt> is not a contact
* known to the underlying protocol provider
* @throws IllegalStateException if the underlying protocol provider is
* not registered/signed on a public service.
* @throws OperationFailedException with code NETWORK_FAILURE if
* retrieving the status fails due to errors experienced during
* network communication
* @param contactIdentifier the identifier of the contact whose status we're
* interested in.
* @return the <tt>PresenceStatus</tt> of the contact with the specified
* <tt>contactIdentifier</tt>
* @throws IllegalArgumentException if the specified
* <tt>contactIdentifier</tt> does not identify a contact known to the
* underlying protocol provider
* @throws IllegalStateException if the underlying protocol provider is not
* registered/signed on a public service
* @throws OperationFailedException with code NETWORK_FAILURE if retrieving
* the status fails due to errors experienced during network communication
*/
public PresenceStatus queryContactStatus(String contactIdentifier) throws
IllegalArgumentException, IllegalStateException,
OperationFailedException
public PresenceStatus queryContactStatus(String contactIdentifier)
throws IllegalArgumentException,
IllegalStateException,
OperationFailedException
{
Presence presence = parentProvider.getConnection().getRoster().
getPresence(contactIdentifier);
/*
* As stated by the javadoc, IllegalStateException signals that the
* ProtocolProviderService is not registered.
*/
assertConnected();
XMPPConnection xmppConnection = parentProvider.getConnection();
if (xmppConnection == null)
{
throw
new IllegalArgumentException(
"The provider/account must be signed on in order to"
+ " query the status of a contact in its roster");
}
Presence presence
= xmppConnection.getRoster().getPresence(contactIdentifier);
if(presence != null)
return jabberStatusToPresenceStatus(presence, parentProvider);
else
return parentProvider.getJabberStatusEnum().getStatus(
JabberStatusEnum.OFFLINE);
{
return
parentProvider.getJabberStatusEnum().getStatus(
JabberStatusEnum.OFFLINE);
}
}
/**
@ -633,30 +654,37 @@ public static Presence.Mode presenceStatusToJabberMode(PresenceStatus status)
/**
* Utility method throwing an exception if the stack is not properly
* initialized.
* @throws java.lang.IllegalStateException if the underlying stack is
* not registered and initialized.
*
* @throws IllegalStateException if the underlying stack is not registered
* and initialized.
*/
private void assertConnected() throws IllegalStateException
void assertConnected()
throws IllegalStateException
{
if (parentProvider == null)
throw new IllegalStateException(
"The provider must be non-null and signed on the Jabber "
+"service before being able to communicate.");
{
throw
new IllegalStateException(
"The provider must be non-null and signed on the"
+ " Jabber service before being able to"
+ " communicate.");
}
if (!parentProvider.isRegistered())
{
// if we are not registered but the current status is online
// change the current status
if(currentStatus.isOnline())
if((currentStatus != null) && currentStatus.isOnline())
{
fireProviderStatusChangeEvent(
currentStatus,
parentProvider.getJabberStatusEnum().getStatus(
JabberStatusEnum.OFFLINE));
JabberStatusEnum.OFFLINE));
}
throw new IllegalStateException(
"The provider must be signed on the Jabber service before "
+"being able to communicate.");
throw
new IllegalStateException(
"The provider must be signed on the Jabber service"
+ " before being able to communicate.");
}
}

@ -214,8 +214,8 @@ public Map<String, OperationSet> getSupportedOperationSets()
/**
* Indicates whether or not this provider is registered
*
* @return true if the provider is currently registered and false
* otherwise.
* @return <tt>true</tt> if the provider is currently registered and
* <tt>false</tt> otherwise.
*/
public boolean isRegistered()
{

Loading…
Cancel
Save