Fix concurrent modification exception due to unlocked access to collection
Change-Id: I8af0759c37f87e958984afe5879747ee7aa385eb
diff --git a/core/net/src/main/java/org/onosproject/net/neighbour/impl/NeighbourResolutionManager.java b/core/net/src/main/java/org/onosproject/net/neighbour/impl/NeighbourResolutionManager.java
index 2a9a187..0101c84 100644
--- a/core/net/src/main/java/org/onosproject/net/neighbour/impl/NeighbourResolutionManager.java
+++ b/core/net/src/main/java/org/onosproject/net/neighbour/impl/NeighbourResolutionManager.java
@@ -291,7 +291,9 @@
@Override
public Map<ConnectPoint, Collection<NeighbourHandlerRegistration>> getHandlerRegistrations() {
- return ImmutableMap.copyOf(Multimaps.asMap(packetHandlers));
+ synchronized (packetHandlers) {
+ return ImmutableMap.copyOf(Multimaps.asMap(packetHandlers));
+ }
}
private void handlePacket(PacketContext context) {
@@ -312,17 +314,16 @@
}
private boolean handleMessage(NeighbourMessageContext context) {
- Collection<NeighbourHandlerRegistration> handlers = packetHandlers.get(context.inPort());
-
- Collection<NeighbourHandlerRegistration> handled = handlers
- .stream()
- .filter(registration -> registration.intf() == null || matches(context, registration.intf()))
- .collect(Collectors.toSet());
-
+ Collection<NeighbourHandlerRegistration> handled;
+ synchronized (packetHandlers) {
+ handled = packetHandlers.get(context.inPort())
+ .stream()
+ .filter(registration -> registration.intf() == null || matches(context, registration.intf()))
+ .collect(Collectors.toSet());
+ }
handled.forEach(registration -> registration.handler().handleMessage(context, hostService));
return !handled.isEmpty();
-
}
/**