Fix some problems discovered by static analysis tools
- Don't throw the base Exception class
- computeIfAbsent always returns an object here, no need to check for null
Change-Id: I1df467b804a632f141fe9e28c5aec1d73c4d1ee3
diff --git a/cli/src/main/java/org/onosproject/cli/net/IntentsDiagnosisCommand.java b/cli/src/main/java/org/onosproject/cli/net/IntentsDiagnosisCommand.java
index 1518137..f31ba18 100644
--- a/cli/src/main/java/org/onosproject/cli/net/IntentsDiagnosisCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/IntentsDiagnosisCommand.java
@@ -114,7 +114,7 @@
svcRefs.workPartitionService.isMine(intent.key(), Key::hash) ? "(Mine)" : "");
}
- private void dumpIntentsByLink(ServiceRefs svcRefs) throws Exception {
+ private void dumpIntentsByLink(ServiceRefs svcRefs) {
Set<Map.Entry<LinkKey, Key>> intentsByLink = getIntentsByLinkSet(svcRefs);
print("* intentsbylink:");
@@ -123,19 +123,25 @@
}
}
- private Set<Map.Entry<LinkKey, Key>> getIntentsByLinkSet(ServiceRefs svcRefs) throws Exception {
+ private Set<Map.Entry<LinkKey, Key>> getIntentsByLinkSet(ServiceRefs svcRefs) {
- ObjectiveTrackerService objTracker = svcRefs.getObjectiveTrackerService();
+ try {
- // Utilizing reflection instead of adding new interface for getting intentsByLink
- Field f = objTracker.getClass().getDeclaredField(FIELD_INTENTS_BY_LINK);
- f.setAccessible(true);
- SetMultimap<LinkKey, Key> intentsByLink = (SetMultimap<LinkKey, Key>) f.get(objTracker);
+ ObjectiveTrackerService objTracker = svcRefs.getObjectiveTrackerService();
- return ImmutableSet.copyOf(intentsByLink.entries());
+ // Utilizing reflection instead of adding new interface for getting intentsByLink
+ Field f = objTracker.getClass().getDeclaredField(FIELD_INTENTS_BY_LINK);
+ f.setAccessible(true);
+ SetMultimap<LinkKey, Key> intentsByLink = (SetMultimap<LinkKey, Key>) f.get(objTracker);
+
+ return ImmutableSet.copyOf(intentsByLink.entries());
+ } catch (NoSuchFieldException | IllegalAccessException ex) {
+ error("error: " + ex);
+ return ImmutableSet.of();
+ }
}
- private void diagnosisP2Pintent(PointToPointIntent intent, ServiceRefs svcRefs) throws Exception {
+ private void diagnosisP2Pintent(PointToPointIntent intent, ServiceRefs svcRefs) {
List<Intent> installableIntents = svcRefs.intentsService().getInstallableIntents(intent.key());
@@ -159,8 +165,7 @@
}
}
- private void checkP2PFlowRuleIntent(PointToPointIntent intent, FlowRuleIntent installable, ServiceRefs svcRefs)
- throws Exception {
+ private void checkP2PFlowRuleIntent(PointToPointIntent intent, FlowRuleIntent installable, ServiceRefs svcRefs) {
final Map<DeviceId, DeviceOnIntent> devs = createDevicesOnP2PIntent(intent, installable);
@@ -256,7 +261,7 @@
}
}
- private void checkIntentsByLink(FlowRuleIntent installable, ServiceRefs svcRefs) throws Exception {
+ private void checkIntentsByLink(FlowRuleIntent installable, ServiceRefs svcRefs) {
Set<Map.Entry<LinkKey, Key>> intentsByLink = getIntentsByLinkSet(svcRefs);
@@ -390,13 +395,10 @@
ConnectPoint dstCp = link.dst();
try {
DeviceOnIntent dev = devMap.computeIfAbsent(srcCp.deviceId(), DeviceOnIntent::new);
- if (dev != null) {
- dev.addEgressLink(link);
- }
+ dev.addEgressLink(link);
+
dev = devMap.computeIfAbsent(dstCp.deviceId(), DeviceOnIntent::new);
- if (dev != null) {
- dev.addIngressLink(link);
- }
+ dev.addIngressLink(link);
} catch (IllegalStateException e) {
print("error: " + e);
}