How do you remove a RosterGroup?

Hi all,

I have a problem in removing a RosterGroup, ex. i have no people left in a RosterGroup and i want to get rid of it. Is there a way to do it? I couldn’'t find an API call for it.

On the contrary, when i want to check my Roster for RosterGroups, it returns me RosterGroups which do not contain any RosterEntries. Is it possible?

Thanks for reply

Something like this is how you would remove a RosterGroup:

Roster r = session.getConnection().getRoster();

Iterator groupIterator = r.getGroups();


RosterGroup rg = (RosterGroup);







Thats a neat idea but i am getting java.lang.UnsupportedOperationException

which means that remove operation is not supported by this iterator. Very strange. Any ideas why?

Thanks again

It’'s pretty clear from the source:

public Iterator getGroups() {

synchronized (groups) {

List groupsList = Collections.unmodifiableList(new ArrayList(groups.values()));

return groupsList.iterator();




In XMPP, a group is automatically non-existent, when there are no entries in that group (since groups are only defined as a property of the contacts). Smack mirrors that by removing them automatically when receiving a roster update when necessary:

// Remove all the groups with no entries. We have to do this because

// RosterGroup.removeEntry removes the entry immediately (locally) and the

// group could remain empty.

for (Iterator it = getGroups(); it.hasNext():wink: {

RosterGroup group = (RosterGroup);

if (group.getEntryCount() == 0) {

synchronized (groups) {






EDIT: added code-tags

To format code simply put your code between

tags. Without the spaces of course

I understand that Group is removed automatically (after some time). How much time is needed for the server to update a client that a group has been removed. I am trying to reload my Roster to initiate update to client and it seems to work, so problem solved.

In any case, there should be an option to enforce removing of a group.

Thanks to all for responding

If a group has not contacts it then no longer exists. You may still see it in the Roster as part of the Smack API but there is no such thing as an empty group in XMPP so therefore no way for the server to recognize this. This group will no longer be there when Smack is restarted, the fact that the group is still there is mostly a convience for developers.

Hope that helps,