Copy if iterating the Collection to remove elements.
- Port can potentially have multiple Device attached
Change-Id: Ib4ee54420120b553cec23c550f79f796c50ae6a5
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/TopologyManager.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/TopologyManager.java
index c18f1cc..d32df8d 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/TopologyManager.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/TopologyManager.java
@@ -554,8 +554,9 @@
Map<ByteBuffer, LinkEvent> oldLinkEvents =
discoveredAddedLinkEvents.get(switchEvent.getDpid());
if (oldLinkEvents != null) {
- for (LinkEvent linkEvent : oldLinkEvents.values())
+ for (LinkEvent linkEvent : new ArrayList<>(oldLinkEvents.values())) {
removeLinkDiscoveryEvent(linkEvent);
+ }
discoveredAddedLinkEvents.remove(switchEvent.getDpid());
}
@@ -563,8 +564,9 @@
Map<ByteBuffer, DeviceEvent> oldDeviceEvents =
discoveredAddedDeviceEvents.get(switchEvent.getDpid());
if (oldDeviceEvents != null) {
- for (DeviceEvent deviceEvent : oldDeviceEvents.values())
+ for (DeviceEvent deviceEvent : new ArrayList<>(oldDeviceEvents.values())) {
removeDeviceDiscoveryEvent(deviceEvent);
+ }
discoveredAddedDeviceEvents.remove(switchEvent.getDpid());
}
}
@@ -616,6 +618,8 @@
// removeLinkDiscoveryEvent() and cannot be iterated
// anymore.
//
+ // XXX If we change our model to allow multiple Link on
+ // a Port, this loop must be fixed to allow continuing.
break;
}
}
@@ -627,11 +631,10 @@
Map<ByteBuffer, DeviceEvent> oldDeviceEvents =
discoveredAddedDeviceEvents.get(portEvent.getDpid());
if (oldDeviceEvents != null) {
- for (DeviceEvent deviceEvent : oldDeviceEvents.values()) {
+ for (DeviceEvent deviceEvent : new ArrayList<>(oldDeviceEvents.values())) {
for (SwitchPort swp : deviceEvent.getAttachmentPoints()) {
if (swp.equals(portEvent.id)) {
removedDeviceEvents.add(deviceEvent);
- break;
}
}
}