Fix ConcurrentModificationException

Change-Id: Ie4c3a56312156ded1cbc2fd8a0e4da822ff57205
diff --git a/apps/segmentrouting/app/src/main/java/org/onosproject/segmentrouting/config/DeviceConfiguration.java b/apps/segmentrouting/app/src/main/java/org/onosproject/segmentrouting/config/DeviceConfiguration.java
index 626109a..704db9a 100644
--- a/apps/segmentrouting/app/src/main/java/org/onosproject/segmentrouting/config/DeviceConfiguration.java
+++ b/apps/segmentrouting/app/src/main/java/org/onosproject/segmentrouting/config/DeviceConfiguration.java
@@ -463,9 +463,12 @@
      */
     public Set<IpPrefix> getSubnets(DeviceId deviceId) {
         SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
-        if (srinfo != null) {
+        if (srinfo != null && srinfo.subnets != null) {
+            // Note: ImmutableSet.Builder.addAll calls the iterator of parameter internally,
+            //       which is not protected by SynchronizedCollection mutex.
             ImmutableSet.Builder<IpPrefix> builder = ImmutableSet.builder();
-            return builder.addAll(srinfo.subnets.values()).build();
+            srinfo.subnets.forEach((k, v) -> builder.add(v));
+            return builder.build();
         }
         return null;
     }