BUG-6237: Topology freezes or slows down due to java.util.concurrent.TimeoutException
[bgpcep.git] / bgp / path-selection-mode / src / main / java / org / opendaylight / protocol / bgp / mode / impl / add / all / paths / AbstractAllPathsRouteEntry.java
index 0378ff2430f6a98b6e1c2f590af2c2b72641b407..cc815b1649c8920f1342ec3342a364826896f0f0 100644 (file)
@@ -34,7 +34,7 @@ abstract class AbstractAllPathsRouteEntry extends AddPathAbstractRouteEntry {
             newBestPathList.add(newBest);
             keyList.remove(newBest.getRouteKey());
             /*we add the rest of path, regardless in what order they are, since this is all path case */
-            for (RouteKey key : keyList) {
+            for (final RouteKey key : keyList) {
                 final int offset = this.offsets.offsetOf(key);
                 final ContainerNode attributes = this.offsets.getValue(this.values, offset);
                 Preconditions.checkNotNull(key.getRouteId(), "Router ID may not be null");
@@ -46,14 +46,15 @@ abstract class AbstractAllPathsRouteEntry extends AddPathAbstractRouteEntry {
             }
         }
 
-        this.bestPathRemoved = new ArrayList<>(this.bestPath);
-        if (this.bestPathRemoved.removeAll(newBestPathList) && !this.bestPathRemoved.isEmpty() || !this.bestPath.equals(newBestPathList)) {
+        if(this.bestPath != null) {
+            this.bestPathRemoved = new ArrayList<>(this.bestPath);
+        }
+
+        if (!newBestPathList.equals(this.bestPath) || this.bestPathRemoved != null && this.bestPathRemoved.removeAll(newBestPathList)) {
             this.bestPath = newBestPathList;
             LOG.trace("Actual Best {}, removed best {}", this.bestPath, this.bestPathRemoved);
             return true;
         }
         return false;
     }
-
-
 }