From aa832ec1f0a572ace856beecf7acfdfa4b3715a2 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Fri, 4 Sep 2015 11:22:52 +0200 Subject: [PATCH] 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. --- .../smackx/privacy/PrivacyListManager.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/PrivacyListManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/PrivacyListManager.java index 360671031..f0d7e7bb9 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/PrivacyListManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/PrivacyListManager.java @@ -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 null 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 null 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 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()); @@ -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)); }