Fix: resolve critical issues reported by sonar
Change-Id: I5ff9363b95608a96e324c294995dbcb79bba1fa9
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingFloatingIpHandler.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingFloatingIpHandler.java
index b34ae9c..16607b1 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingFloatingIpHandler.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingFloatingIpHandler.java
@@ -144,7 +144,8 @@
boolean install) {
Network osNet = osNetworkService.network(osPort.getNetworkId());
if (osNet == null) {
- final String error = String.format(ERR_FLOW + "no network(%s) exists",
+ final String errorFormat = ERR_FLOW + "no network(%s) exists";
+ final String error = String.format(errorFormat,
floatingIp.getFloatingIpAddress(),
osPort.getNetworkId());
throw new IllegalStateException(error);
@@ -153,7 +154,8 @@
MacAddress srcMac = MacAddress.valueOf(osPort.getMacAddress());
InstancePort instPort = instancePortService.instancePort(srcMac);
if (instPort == null) {
- final String error = String.format(ERR_FLOW + "no host(MAC:%s) found",
+ final String errorFormat = ERR_FLOW + "no host(MAC:%s) found";
+ final String error = String.format(errorFormat,
floatingIp.getFloatingIpAddress(), srcMac);
throw new IllegalStateException(error);
}
@@ -222,13 +224,13 @@
throw new IllegalStateException(error);
}
if (osNet.getNetworkType() == NetworkType.VXLAN && cNode.dataIp() == null) {
- final String error = String.format(ERR_FLOW +
- "VXLAN mode is not ready for %s", floatingIp, cNode.hostname());
+ final String errorFormat = ERR_FLOW + "VXLAN mode is not ready for %s";
+ final String error = String.format(errorFormat, floatingIp, cNode.hostname());
throw new IllegalStateException(error);
}
if (osNet.getNetworkType() == NetworkType.VLAN && cNode.vlanIntf() == null) {
- final String error = String.format(ERR_FLOW +
- "VLAN mode is not ready for %s", floatingIp, cNode.hostname());
+ final String errorFormat = ERR_FLOW + "VLAN mode is not ready for %s";
+ final String error = String.format(errorFormat, floatingIp, cNode.hostname());
throw new IllegalStateException(error);
}
@@ -460,7 +462,8 @@
private void associateFloatingIp(NetFloatingIP osFip) {
Port osPort = osNetworkService.port(osFip.getPortId());
if (osPort == null) {
- final String error = String.format(ERR_FLOW + "port(%s) not found",
+ final String errorFormat = ERR_FLOW + "port(%s) not found";
+ final String error = String.format(errorFormat,
osFip.getFloatingIpAddress(), osFip.getPortId());
throw new IllegalStateException(error);
}
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingHandler.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingHandler.java
index 11b3247..6d2f70b 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingHandler.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingHandler.java
@@ -108,7 +108,6 @@
private static final String MSG_ENABLED = "Enabled ";
private static final String MSG_DISABLED = "Disabled ";
- private static final String ERR_SET_FLOWS = "Failed to set flows for router %s:";
private static final String ERR_UNSUPPORTED_NET_TYPE = "Unsupported network type";
private static final boolean USE_STATEFUL_SNAT = false;
@@ -237,7 +236,7 @@
Subnet osSubnet = osNetworkService.subnet(osRouterIface.getSubnetId());
if (osSubnet == null) {
final String error = String.format(
- ERR_SET_FLOWS + "subnet %s does not exist",
+ "Failed to set flows for router %s: subnet %s does not exist",
osRouterIface.getId(),
osRouterIface.getSubnetId());
throw new IllegalStateException(error);
@@ -261,7 +260,7 @@
Subnet osSubnet = osNetworkService.subnet(osRouterIface.getSubnetId());
if (osSubnet == null) {
final String error = String.format(
- ERR_SET_FLOWS + "subnet %s does not exist",
+ "Failed to set flows for router %s: subnet %s does not exist",
osRouterIface.getId(),
osRouterIface.getSubnetId());
throw new IllegalStateException(error);
@@ -421,8 +420,8 @@
install));
break;
default:
- final String error = String.format(
- ERR_UNSUPPORTED_NET_TYPE + "%s",
+ final String error = String.format("%s %s",
+ ERR_UNSUPPORTED_NET_TYPE,
network.getNetworkType().toString());
throw new IllegalStateException(error);
}
@@ -615,8 +614,8 @@
install);
break;
default:
- final String error = String.format(
- ERR_UNSUPPORTED_NET_TYPE + "%s",
+ final String error = String.format("%s %s",
+ ERR_UNSUPPORTED_NET_TYPE,
networkType.toString());
throw new IllegalStateException(error);
}
@@ -645,8 +644,8 @@
sBuilder.matchVlanId(VlanId.vlanId(segmentId));
break;
default:
- final String error = String.format(
- ERR_UNSUPPORTED_NET_TYPE + "%s",
+ final String error = String.format("%s %s",
+ ERR_UNSUPPORTED_NET_TYPE,
networkType.toString());
throw new IllegalStateException(error);
}
@@ -811,8 +810,8 @@
.matchEthDst(osNodeService.node(deviceId).vlanPortMac());
break;
default:
- final String error = String.format(
- ERR_UNSUPPORTED_NET_TYPE + "%s",
+ final String error = String.format("%s %s",
+ ERR_UNSUPPORTED_NET_TYPE,
networkType.toString());
throw new IllegalStateException(error);
}
@@ -870,8 +869,8 @@
sBuilder.matchVlanId(VlanId.vlanId(segmentId));
break;
default:
- final String error = String.format(
- ERR_UNSUPPORTED_NET_TYPE + "%s",
+ final String error = String.format("%s %s",
+ ERR_UNSUPPORTED_NET_TYPE,
networkType.toString());
throw new IllegalStateException(error);
}
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingSnatHandler.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingSnatHandler.java
index 5ea8442..9f792bd 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingSnatHandler.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingSnatHandler.java
@@ -285,8 +285,8 @@
TpPort patPort, IpAddress externalIp, MacAddress externalPeerRouterMac) {
Network osNet = osNetworkService.network(srcInstPort.networkId());
if (osNet == null) {
- final String error = String.format(ERR_PACKETIN + "network %s not found",
- srcInstPort.networkId());
+ final String error = String.format("%s network %s not found",
+ ERR_PACKETIN, srcInstPort.networkId());
throw new IllegalStateException(error);
}
@@ -333,9 +333,8 @@
.setEthSrc(DEFAULT_GATEWAY_MAC);
break;
default:
- final String error = String.format(
- ERR_UNSUPPORTED_NET_TYPE + "%s",
- networkType.toString());
+ final String error = String.format("%s %s",
+ ERR_UNSUPPORTED_NET_TYPE, networkType.toString());
throw new IllegalStateException(error);
}
@@ -373,8 +372,8 @@
tmpBuilder.setOutput(gNode.vlanPortNum());
break;
default:
- final String error = String.format(ERR_UNSUPPORTED_NET_TYPE + "%s",
- networkType.toString());
+ final String error = String.format("%s %s",
+ ERR_UNSUPPORTED_NET_TYPE, networkType.toString());
throw new IllegalStateException(error);
}
@@ -412,8 +411,8 @@
tBuilder.popVlan();
break;
default:
- final String error = String.format(ERR_UNSUPPORTED_NET_TYPE + "%s",
- networkType.toString());
+ final String error = String.format("%s %s",
+ ERR_UNSUPPORTED_NET_TYPE, networkType.toString());
throw new IllegalStateException(error);
}
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingHandler.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingHandler.java
index 37cabf4..3cba0e3 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingHandler.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingHandler.java
@@ -74,7 +74,7 @@
private final Logger log = getLogger(getClass());
- private static final String ERR_SET_FLOWS = "Failed to set flows for %s: ";
+ private static final String ERR_SET_FLOWS_VNI = "Failed to set flows for %s: Failed to get VNI for %s";
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
CoreService coreService;
@@ -341,9 +341,9 @@
Network osNet = osNetworkService.network(instPort.networkId());
if (osNet == null || Strings.isNullOrEmpty(osNet.getProviderSegID())) {
- final String error = String.format(
- ERR_SET_FLOWS + "Failed to get VNI for %s",
- instPort, osNet == null ? "<none>" : osNet.getName());
+ final String error =
+ String.format(ERR_SET_FLOWS_VNI,
+ instPort, osNet == null ? "<none>" : osNet.getName());
throw new IllegalStateException(error);
}
@@ -354,9 +354,9 @@
private Long getVni(InstancePort instPort) {
Network osNet = osNetworkService.network(instPort.networkId());
if (osNet == null || Strings.isNullOrEmpty(osNet.getProviderSegID())) {
- final String error = String.format(
- ERR_SET_FLOWS + "Failed to get VNI for %s",
- instPort, osNet == null ? "<none>" : osNet.getName());
+ final String error =
+ String.format(ERR_SET_FLOWS_VNI,
+ instPort, osNet == null ? "<none>" : osNet.getName());
throw new IllegalStateException(error);
}
return Long.valueOf(osNet.getProviderSegID());