[FELIX-4783] ConcurrentModificationException when stopping gogo
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1656672 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandProcessorImpl.java b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandProcessorImpl.java
index 83b3d15..9edc62c 100644
--- a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandProcessorImpl.java
+++ b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandProcessorImpl.java
@@ -72,10 +72,7 @@
{
synchronized (sessions)
{
- if (sessions.remove(session) != null)
- {
- System.out.println("CLOSED: " + session);
- }
+ sessions.remove(session);
}
}
@@ -84,10 +81,13 @@
synchronized (sessions)
{
stopped = true;
- for (CommandSession session : sessions.keySet())
+ // Create a copy, as calling session.close() will remove the session from the map
+ CommandSession[] toClose = this.sessions.keySet().toArray(new CommandSession[this.sessions.size()]);
+ for (CommandSession session : toClose)
{
session.close();
}
+ // Just in case...
sessions.clear();
}
}