Handle cases where no privacy lists are set.

The is when no default or active list is, then don't perform a privacy
list request where list name is 'null'.

Fixes SMACK-697.
This commit is contained in:
Florian Schmaus 2015-09-04 11:22:52 +02:00
parent 8aa3f94c90
commit aa832ec1f0
1 changed files with 12 additions and 3 deletions

View File

@ -41,6 +41,7 @@ import org.jivesoftware.smack.iqrequest.AbstractIqRequestHandler;
import org.jivesoftware.smack.iqrequest.IQRequestHandler.Mode;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.privacy.filter.SetActiveListFilter;
import org.jivesoftware.smackx.privacy.filter.SetDefaultListFilter;
@ -267,7 +268,7 @@ public class PrivacyListManager extends Manager {
}
/**
* Answer the active privacy list.
* Answer the active privacy list. Returns <code>null</code> if there is no active list.
*
* @return the privacy list of the active list.
* @throws XMPPErrorException
@ -277,6 +278,9 @@ public class PrivacyListManager extends Manager {
public PrivacyList getActiveList() throws NoResponseException, XMPPErrorException, NotConnectedException {
Privacy privacyAnswer = this.getPrivacyWithListNames();
String listName = privacyAnswer.getActiveName();
if (StringUtils.isNullOrEmpty(listName)) {
return null;
}
boolean isDefaultAndActive = listName != null && listName.equals(privacyAnswer.getDefaultName());
return new PrivacyList(true, isDefaultAndActive, listName, getPrivacyListItems(listName));
}
@ -298,7 +302,7 @@ public class PrivacyListManager extends Manager {
}
/**
* Answer the default privacy list.
* Answer the default privacy list. Returns <code>null</code> if there is no default list.
*
* @return the privacy list of the default list.
* @throws XMPPErrorException
@ -308,7 +312,10 @@ public class PrivacyListManager extends Manager {
public PrivacyList getDefaultList() throws NoResponseException, XMPPErrorException, NotConnectedException {
Privacy privacyAnswer = this.getPrivacyWithListNames();
String listName = privacyAnswer.getDefaultName();
boolean isDefaultAndActive = listName != null && listName.equals(privacyAnswer.getActiveName());
if (StringUtils.isNullOrEmpty(listName)) {
return null;
}
boolean isDefaultAndActive = listName.equals(privacyAnswer.getActiveName());
return new PrivacyList(isDefaultAndActive, true, listName, getPrivacyListItems(listName));
}
@ -359,6 +366,7 @@ public class PrivacyListManager extends Manager {
* @throws NotConnectedException
*/
private List<PrivacyItem> getPrivacyListItems(String listName) throws NoResponseException, XMPPErrorException, NotConnectedException {
assert StringUtils.isNotEmpty(listName);
// The request of the list is an privacy message with an empty list
Privacy request = new Privacy();
request.setPrivacyList(listName, new ArrayList<PrivacyItem>());
@ -379,6 +387,7 @@ public class PrivacyListManager extends Manager {
* @throws NotConnectedException
*/
public PrivacyList getPrivacyList(String listName) throws NoResponseException, XMPPErrorException, NotConnectedException {
listName = StringUtils.requireNotNullOrEmpty(listName, "List name must not be null");
return new PrivacyList(false, false, listName, getPrivacyListItems(listName));
}