Skip to content

Conversation

@stokito
Copy link
Contributor

@stokito stokito commented Nov 15, 2025

The allocation might be needed (I guess) to avoid concurrency problems. The chatRoomList is changed in two places: in the addChatRoom() that is synchronized and cleanupChatRoom() that is not synchronized. So just to be sure I made it synchronized too.

The chatRoomList is added in the synchronized addChatRoom() so removing of the fields also should be synchronized
@stokito
Copy link
Contributor Author

stokito commented Nov 15, 2025

It looks like some pattern or remains after some refactoring because there are other places with such iteration over an ArrayList copy:
org/jivesoftware/spark/SessionManager.java:206
org/jivesoftware/spark/filetransfer/SparkTransferManager.java:695
org/jivesoftware/spark/ui/ChatRoom.java:1139
org/jivesoftware/spark/ui/ContactGroup.java:270
org/jivesoftware/spark/ui/ContactGroup.java:284
org/jivesoftware/spark/ui/ContactGroup.java:416
org/jivesoftware/spark/ui/ContactList.java:379

@Fishbowler
Copy link
Member

Does that mean that this should go to draft, or should this be tackled in another PR?

Make it similar to getContactItems() that returns a sorted copy.
Remove ContactList.ContactItemComparator as it's the same as the ContactGroup.itemComparator.
Remove sorting of the group.getOfflineContacts() results in the BroadcastDialog()
…ationListeners) since getInvitationListeners() reruns an unmodifiable list
@stokito
Copy link
Contributor Author

stokito commented Dec 5, 2025

It creates a copy of the list (new ArrayList<>(this.presenceListeners)) to avoid concurrent modification issues if a listener modifies the list during iteration.

I can't replace all the places where this happens but for listeners we have a few options:

The CopyOnWriteArrayList is already used in some places for listeners also an AI recommended to use it.

So I changed all the places where I found a list of listeners to the CopyOnWriteArrayList so that same pattern will be used everywhere. I can't properly test it but Sparks looks working fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants