Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPE on contact popup #868

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions core/src/main/java/org/jivesoftware/spark/ui/ContactList.java
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ public ContactGroup getContactGroup(String groupName) {
ContactGroup cGroup = null;

for (ContactGroup contactGroup : groupList) {
if (contactGroup.getGroupName().equals(groupName)) {
if (contactGroup.getGroupName().equalsIgnoreCase(groupName)) {
cGroup = contactGroup;
break;
} else {
Expand Down Expand Up @@ -1178,15 +1178,13 @@ public ContactGroup getParentGroup(String groupName) {
* @return the nested ContactGroup. If not found, null will be returned.
*/
private ContactGroup getSubContactGroup(ContactGroup group, String groupName) {
final Iterator<ContactGroup> contactGroups = group.getContactGroups().iterator();
ContactGroup grp = null;

while (contactGroups.hasNext()) {
ContactGroup contactGroup = contactGroups.next();
if (contactGroup.getGroupName().equals(groupName)) {
for (ContactGroup contactGroup : group.getContactGroups()) {
if (contactGroup.getGroupName().equalsIgnoreCase(groupName)) {
grp = contactGroup;
break;
} else if (contactGroup.getContactGroups().size() > 0) {
} else if (!contactGroup.getContactGroups().isEmpty()) {
grp = getSubContactGroup(contactGroup, groupName);
if (grp != null) {
break;
Expand Down Expand Up @@ -1518,9 +1516,12 @@ public void actionPerformed(ActionEvent actionEvent) {

String groupName = item.getGroupName();
ContactGroup contactGroup = getContactGroup(groupName);
if (contactGroup == null) {
Log.error("Unable to get contact group for " + groupName);
}

// Only show "Remove Contact From Group" if the user belongs to more than one group.
if (!contactGroup.isSharedGroup() && !contactGroup.isOfflineGroup() && contactGroup != getUnfiledGroup()) {
if (contactGroup != null && !contactGroup.isSharedGroup() && !contactGroup.isOfflineGroup() && contactGroup != getUnfiledGroup()) {
Roster roster = Roster.getInstanceFor(SparkManager.getConnection());
RosterEntry entry = roster.getEntry(item.getJid().asBareJid());
if (entry != null) {
Expand Down Expand Up @@ -1561,7 +1562,9 @@ public void actionPerformed(ActionEvent e) {

// See if we should disable the option to remove a contact
if (!Default.getBoolean(Default.DISABLE_REMOVALS) && Enterprise.containsFeature(Enterprise.REMOVALS_FEATURE)) {
if (!contactGroup.isSharedGroup() && !isInSharedGroup) popup.add(removeAction);
if (contactGroup != null && !contactGroup.isSharedGroup() && !isInSharedGroup) {
popup.add(removeAction);
}
}

// See if we should disable the option to rename a contact
Expand Down
Loading