From 2df479225932d3e8ee99a601182ed01996a54666 Mon Sep 17 00:00:00 2001 From: Dor Bivas Date: Tue, 15 Apr 2014 17:14:48 +0300 Subject: server: don't panic on ConcurrentModificationException If the connections list changes durreng sending of a message, abort the sending but don't panic further than that. --- src/Server/CommandsTable.java | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Server/CommandsTable.java b/src/Server/CommandsTable.java index 25afadf..ba80ade 100644 --- a/src/Server/CommandsTable.java +++ b/src/Server/CommandsTable.java @@ -1,5 +1,6 @@ package Server; import java.io.IOException; +import java.util.ConcurrentModificationException; import java.util.Hashtable; import java.util.Iterator; @@ -98,16 +99,23 @@ class CommandPrivmsg extends Command Iterator iter = ChatServer.server.getConnectionIterator(); - while (iter.hasNext()) + try { - Connection con = iter.next(); - - if (client.IfMyCon(con)) + while (iter.hasNext()) { - continue; + Connection con = iter.next(); + + if (client.IfMyCon(con)) + { + continue; + } + ports += con.toString(); + this.printUser(con.getClient(), client, "PRIVMSG " + starr[0] + " :" + line); } - ports += con.toString(); - this.printUser(con.getClient(), client, "PRIVMSG " + starr[0] + " :" + line); + } + catch (java.util.ConcurrentModificationException e) + { + System.err.println("concurrency error, privmsg may not be fully delivered\n"); } System.out.println("printed message to ports: " + ports); } -- cgit v1.2.3