Fix NPE when pending operations are not present
(due to possible race condition)
2019-02-15 11:18:45,407 | WARN | -event-barrier-1 | LocalCache | 94 | Exception thrown by removal listener
java.lang.NullPointerException
at org.onosproject.net.flow.impl.FlowRuleManager$InternalStoreDelegate.notify(FlowRuleManager.java:639)
at org.onosproject.net.flow.impl.FlowRuleManager$InternalStoreDelegate.notify(FlowRuleManager.java:591)
at org.onosproject.store.AbstractStore.notifyDelegate(AbstractStore.java:58)
at org.onosproject.store.flow.impl.ECFlowRuleStore.batchOperationComplete(ECFlowRuleStore.java:638)
at org.onosproject.net.flow.impl.FlowRuleManager$InternalFlowRuleProviderService.batchOperationCompleted(FlowRuleManager.java:577)
at org.onosproject.provider.of.flow.impl.OpenFlowRuleProvider.lambda$createBatchCache$0(OpenFlowRuleProvider.java:231)
at com.google.common.cache.LocalCache.processPendingNotifications(LocalCache.java:1967)[94:com.google.guava:22.0.0]
at com.google.common.cache.LocalCache$Segment.runUnlockedCleanup(LocalCache.java:3642)[94:com.google.guava:22.0.0]
at com.google.common.cache.LocalCache$Segment.postWriteCleanup(LocalCache.java:3618)[94:com.google.guava:22.0.0]
at com.google.common.cache.LocalCache$Segment.remove(LocalCache.java:3246)[94:com.google.guava:22.0.0]
at com.google.common.cache.LocalCache.remove(LocalCache.java:4413)[94:com.google.guava:22.0.0]
at com.google.common.cache.LocalCache$LocalManualCache.invalidate(LocalCache.java:5081)[94:com.google.guava:22.0.0]
at org.onosproject.provider.of.flow.impl.OpenFlowRuleProvider$InternalFlowProvider.handleMessage(OpenFlowRuleProvider.java:466)[170:org.onosproject.onos-providers-openflow-flow:1.12.2.SNAPSHOT]
at org.onosproject.openflow.controller.impl.OpenFlowControllerImpl$OFMessageHandler.run(OpenFlowControllerImpl.java:773)[167:org.onosproject.onos-protocols-openflow-ctl:1.12.2.SNAPSHOT]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)[:1.8.0_192]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)[:1.8.0_192]
at java.lang.Thread.run(Thread.java:748)[:1.8.0_192]
Change-Id: I6eb64524c5e209c4a6d6a6f147d7ab0c86137246
diff --git a/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleManager.java b/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleManager.java
index dcc7f59..e7f3ef6 100644
--- a/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleManager.java
+++ b/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleManager.java
@@ -635,17 +635,18 @@
break;
case BATCH_OPERATION_COMPLETED:
-
+ // Operation completed, let's retrieve the processor and trigger the callback
FlowOperationsProcessor fops = pendingFlowOperations.remove(
event.subject().batchId());
- if (event.result().isSuccess()) {
- if (fops != null) {
+ if (fops != null) {
+ if (event.result().isSuccess()) {
fops.satisfy(event.deviceId());
+ } else {
+ fops.fail(event.deviceId(), event.result().failedItems());
}
} else {
- fops.fail(event.deviceId(), event.result().failedItems());
+ log.warn("Unable to find flow operations processor for batch: {}", event.subject().batchId());
}
-
break;
default: