Merge pull request #431 from y-higuchi/fix_findbug_issues
Fix findbug issues
diff --git a/src/main/java/net/floodlightcontroller/core/internal/Controller.java b/src/main/java/net/floodlightcontroller/core/internal/Controller.java
index 9d4ac9a..44510a7 100644
--- a/src/main/java/net/floodlightcontroller/core/internal/Controller.java
+++ b/src/main/java/net/floodlightcontroller/core/internal/Controller.java
@@ -746,7 +746,7 @@
}
if (is_core_switch) {
sw.setAttribute(IOFSwitch.SWITCH_IS_CORE_SWITCH,
- new Boolean(true));
+ true);
}
}
sw.removeAttribute(IOFSwitch.SWITCH_DESCRIPTION_FUTURE);
@@ -2352,7 +2352,7 @@
// new controller node IP
addedControllerNodeIPs.put(controllerID, discoveredIP);
}
- else if (curIP != discoveredIP) {
+ else if (curIP.equals(discoveredIP)) {
// IP changed
removedControllerNodeIPs.put(controllerID, curIP);
addedControllerNodeIPs.put(controllerID, discoveredIP);
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java
index 4130da6..2c5f4ba 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java
@@ -332,11 +332,7 @@
if ((flowUserState != null)
&& flowUserState.equals("FE_USER_DELETE")) {
Iterable<IFlowEntry> flowEntries = flowPathObj.getFlowEntries();
- boolean empty = true; // TODO: an ugly hack
- for (IFlowEntry flowEntryObj : flowEntries) {
- empty = false;
- break;
- }
+ final boolean empty = !flowEntries.iterator().hasNext();
if (empty)
deleteFlows.add(flowPathObj);
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/linkdiscovery/web/LinksResource.java b/src/main/java/net/onrc/onos/ofcontroller/linkdiscovery/web/LinksResource.java
index c522a05..3c97e6a 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/linkdiscovery/web/LinksResource.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/linkdiscovery/web/LinksResource.java
@@ -3,6 +3,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import net.floodlightcontroller.routing.Link;
@@ -23,8 +24,9 @@
if (ld != null) {
links.putAll(ld.getLinks());
- for (Link link: links.keySet()) {
- LinkInfo info = links.get(link);
+ for(Entry<Link, LinkInfo> e : links.entrySet()) {
+ Link link = e.getKey();
+ LinkInfo info = e.getValue();
LinkWithType lwt = new LinkWithType(link,
info.getSrcPortState(),
info.getDstPortState(),
diff --git a/src/main/java/net/onrc/onos/ofcontroller/util/DataPath.java b/src/main/java/net/onrc/onos/ofcontroller/util/DataPath.java
index dec70e3..e807b56 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/util/DataPath.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/util/DataPath.java
@@ -116,19 +116,18 @@
* inPort/dpid/outPort;inPort/dpid/outPort;...
*/
public String dataPathSummary() {
- String resultStr = new String();
+ StringBuilder resultStr = new StringBuilder(5+1+20+1+5+1);
if (this.flowEntries != null) {
for (FlowEntry flowEntry : this.flowEntries) {
// The data path summary string
- resultStr = resultStr +
- flowEntry.inPort().toString() + "/"
- + flowEntry.dpid().toString() + "/" +
- flowEntry.outPort().toString() + ";";
+ resultStr.append(flowEntry.inPort().toString()).append('/')
+ .append(flowEntry.dpid().toString()).append('/')
+ .append(flowEntry.outPort().toString()).append(';');
}
}
- if (resultStr.isEmpty())
- resultStr = "X"; // Invalid shortest-path
- return resultStr;
+ if (resultStr.length() == 0)
+ resultStr.append("X"); // Invalid shortest-path
+ return resultStr.toString();
}
/**
diff --git a/src/main/java/net/onrc/onos/ofcontroller/util/FlowEntryAction.java b/src/main/java/net/onrc/onos/ofcontroller/util/FlowEntryAction.java
index 1f8849a..a1163c8 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/util/FlowEntryAction.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/util/FlowEntryAction.java
@@ -48,7 +48,7 @@
/**
* Action structure for ACTION_OUTPUT: Output to switch port.
*/
- public class ActionOutput {
+ public static class ActionOutput {
private Port port; // Output port
private short maxLen; // Max. length (in bytes) to send to controller
// if the port is set to PORT_CONTROLLER
@@ -198,7 +198,7 @@
/**
* Action structure for ACTION_SET_VLAN_VID: Set the 802.1q VLAN id
*/
- public class ActionSetVlanId {
+ public static class ActionSetVlanId {
private short vlanId; // The VLAN ID to set
/**
@@ -296,7 +296,7 @@
/**
* Action structure for ACTION_SET_VLAN_PCP: Set the 802.1q priority
*/
- public class ActionSetVlanPriority {
+ public static class ActionSetVlanPriority {
private byte vlanPriority; // The VLAN priority to set
/**
@@ -394,7 +394,7 @@
/**
* Action structure for ACTION_STRIP_VLAN: Strip the 802.1q header
*/
- public class ActionStripVlan {
+ public static class ActionStripVlan {
private boolean stripVlan; // If true, strip the VLAN header
/**
@@ -489,7 +489,7 @@
* Action structure for ACTION_SET_DL_SRC and ACTION_SET_DL_DST:
* Set the Ethernet source/destination address.
*/
- public class ActionSetEthernetAddr {
+ public static class ActionSetEthernetAddr {
private MACAddress addr; // The MAC address to set
/**
@@ -589,7 +589,7 @@
* Action structure for ACTION_SET_NW_SRC and ACTION_SET_NW_DST:
* Set the IPv4 source/destination address.
*/
- public class ActionSetIPv4Addr {
+ public static class ActionSetIPv4Addr {
private IPv4 addr; // The IPv4 address to set
/**
@@ -689,7 +689,7 @@
* Action structure for ACTION_SET_NW_TOS:
* Set the IP ToS (DSCP field, 6 bits).
*/
- public class ActionSetIpToS {
+ public static class ActionSetIpToS {
private byte ipToS; // The IP ToS to set DSCP field, 6 bits)
/**
@@ -788,7 +788,7 @@
* Action structure for ACTION_SET_TP_SRC and ACTION_SET_TP_DST:
* Set the TCP/UDP source/destination port.
*/
- public class ActionSetTcpUdpPort {
+ public static class ActionSetTcpUdpPort {
private short port; // The TCP/UDP port to set
/**
@@ -886,7 +886,7 @@
/**
* Action structure for ACTION_ENQUEUE: Output to queue on port.
*/
- public class ActionEnqueue {
+ public static class ActionEnqueue {
private Port port; // Port that queue belongs. Should
// refer to a valid physical port
// (i.e. < PORT_MAX) or PORT_IN_PORT
diff --git a/src/main/java/net/onrc/onos/ofcontroller/util/FlowEntryMatch.java b/src/main/java/net/onrc/onos/ofcontroller/util/FlowEntryMatch.java
index a721ff2..fd41d09 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/util/FlowEntryMatch.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/util/FlowEntryMatch.java
@@ -16,7 +16,7 @@
/**
* A class for storing a value to match.
*/
- class Field<T> {
+ static class Field<T> {
/**
* Default constructor.
*/
diff --git a/src/main/java/net/onrc/onos/ofcontroller/util/FlowPathFlags.java b/src/main/java/net/onrc/onos/ofcontroller/util/FlowPathFlags.java
index 63241f0..4bbd399 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/util/FlowPathFlags.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/util/FlowPathFlags.java
@@ -9,10 +9,10 @@
private long flags;
// Discard the first-hop Flow Entry
- private final long DISCARD_FIRST_HOP_ENTRY = (1 << 0);
+ private static final long DISCARD_FIRST_HOP_ENTRY = (1 << 0);
// Keep only the first-hop Flow Entry
- private final long KEEP_ONLY_FIRST_HOP_ENTRY = (1 << 1);
+ private static final long KEEP_ONLY_FIRST_HOP_ENTRY = (1 << 1);
/**
* Default constructor.
diff --git a/src/main/java/org/openflow/util/HexString.java b/src/main/java/org/openflow/util/HexString.java
index 5777612..07cc1f7 100644
--- a/src/main/java/org/openflow/util/HexString.java
+++ b/src/main/java/org/openflow/util/HexString.java
@@ -27,35 +27,35 @@
*/
public static String toHexString(byte[] bytes) {
int i;
- String ret = "";
+ StringBuilder ret = new StringBuilder(8*2+7);
String tmp;
for(i=0; i< bytes.length; i++) {
if(i> 0)
- ret += ":";
+ ret.append(':');
tmp = Integer.toHexString(U8.f(bytes[i]));
if (tmp.length() == 1)
- ret += "0";
- ret += tmp;
+ ret.append('0');
+ ret.append(tmp);
}
- return ret;
+ return ret.toString();
}
public static String toHexString(long val, int padTo) {
char arr[] = Long.toHexString(val).toCharArray();
- String ret = "";
+ StringBuilder ret = new StringBuilder(8*2+7);
// prepend the right number of leading zeros
int i = 0;
for (; i < (padTo * 2 - arr.length); i++) {
- ret += "0";
+ ret.append('0');
if ((i % 2) == 1)
- ret += ":";
+ ret.append(':');
}
for (int j = 0; j < arr.length; j++) {
- ret += arr[j];
+ ret.append(arr[j]);
if ((((i + j) % 2) == 1) && (j < (arr.length - 1)))
- ret += ":";
+ ret.append(':');
}
- return ret;
+ return ret.toString();
}
public static String toHexString(long val) {
diff --git a/src/test/java/net/onrc/onos/ofcontroller/util/FlowEntryActionTest.java b/src/test/java/net/onrc/onos/ofcontroller/util/FlowEntryActionTest.java
index 4db734c..d816517 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/util/FlowEntryActionTest.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/util/FlowEntryActionTest.java
@@ -19,7 +19,7 @@
@Test
public void testSetActionOutputActionOutput(){
FlowEntryAction act = new FlowEntryAction();
- ActionOutput actout = act.new ActionOutput(new Port((short)42));
+ ActionOutput actout = new FlowEntryAction.ActionOutput(new Port((short)42));
act.setActionOutput(actout);
assertEquals("action output",FlowEntryAction.ActionValues.ACTION_OUTPUT , act.actionType());
@@ -68,7 +68,7 @@
@Test
public void testSetActionSetVlanIdActionSetVlanId(){
FlowEntryAction act = new FlowEntryAction();
- ActionSetVlanId actVlan = act.new ActionSetVlanId((short)42);
+ ActionSetVlanId actVlan = new FlowEntryAction.ActionSetVlanId((short)42);
act.setActionSetVlanId(actVlan);
assertEquals("action type",FlowEntryAction.ActionValues.ACTION_SET_VLAN_VID , act.actionType());
@@ -100,7 +100,7 @@
@Test
public void testSetActionSetVlanPriorityActionSetVlanPriority(){
FlowEntryAction act = new FlowEntryAction();
- ActionSetVlanPriority actVlan = act.new ActionSetVlanPriority((byte)42);
+ ActionSetVlanPriority actVlan = new FlowEntryAction.ActionSetVlanPriority((byte)42);
act.setActionSetVlanPriority(actVlan);
assertEquals("action type",FlowEntryAction.ActionValues.ACTION_SET_VLAN_PCP , act.actionType());
@@ -132,7 +132,7 @@
@Test
public void testSetActionStripVlanActionStripVlan(){
FlowEntryAction act = new FlowEntryAction();
- ActionStripVlan actVlan = act.new ActionStripVlan();
+ ActionStripVlan actVlan = new FlowEntryAction.ActionStripVlan();
act.setActionStripVlan(actVlan);
assertEquals("action type",FlowEntryAction.ActionValues.ACTION_STRIP_VLAN , act.actionType());
@@ -165,7 +165,7 @@
public void testSetActionSetEthernetSrcAddrActionSetEthernetAddr(){
FlowEntryAction act = new FlowEntryAction();
byte[] mac = { 1, 2, 3, 4, 5, 6 };
- ActionSetEthernetAddr setEth = act.new ActionSetEthernetAddr(new MACAddress(mac));
+ ActionSetEthernetAddr setEth = new FlowEntryAction.ActionSetEthernetAddr(new MACAddress(mac));
act.setActionSetEthernetSrcAddr( setEth );
assertEquals("action type",FlowEntryAction.ActionValues.ACTION_SET_DL_SRC , act.actionType());
@@ -200,7 +200,7 @@
public void testSetActionSetEthernetDstAddrActionSetEthernetAddr(){
FlowEntryAction act = new FlowEntryAction();
byte[] mac = { 1, 2, 3, 4, 5, 6 };
- ActionSetEthernetAddr setEth = act.new ActionSetEthernetAddr(new MACAddress(mac));
+ ActionSetEthernetAddr setEth = new FlowEntryAction.ActionSetEthernetAddr(new MACAddress(mac));
act.setActionSetEthernetDstAddr( setEth );
assertEquals("action type",FlowEntryAction.ActionValues.ACTION_SET_DL_DST , act.actionType());
@@ -233,7 +233,7 @@
@Test
public void testSetActionSetIPv4SrcAddrActionSetIPv4Addr(){
FlowEntryAction act = new FlowEntryAction();
- ActionSetIPv4Addr setIp = act.new ActionSetIPv4Addr(new IPv4("127.0.0.1"));
+ ActionSetIPv4Addr setIp = new FlowEntryAction.ActionSetIPv4Addr(new IPv4("127.0.0.1"));
act.setActionSetIPv4SrcAddr( setIp );
assertEquals("action type",FlowEntryAction.ActionValues.ACTION_SET_NW_SRC , act.actionType());
@@ -266,7 +266,7 @@
@Test
public void testSetActionSetIPv4DstAddrActionSetIPv4Addr(){
FlowEntryAction act = new FlowEntryAction();
- ActionSetIPv4Addr setIp = act.new ActionSetIPv4Addr(new IPv4("127.0.0.1"));
+ ActionSetIPv4Addr setIp = new FlowEntryAction.ActionSetIPv4Addr(new IPv4("127.0.0.1"));
act.setActionSetIPv4DstAddr( setIp );
assertEquals("action type",FlowEntryAction.ActionValues.ACTION_SET_NW_DST , act.actionType());
@@ -298,7 +298,7 @@
@Test
public void testSetActionSetIpToSActionSetIpToS(){
FlowEntryAction act = new FlowEntryAction();
- ActionSetIpToS setIpTos = act.new ActionSetIpToS((byte)42);
+ ActionSetIpToS setIpTos = new FlowEntryAction.ActionSetIpToS((byte)42);
act.setActionSetIpToS( setIpTos );
assertEquals("action type",FlowEntryAction.ActionValues.ACTION_SET_NW_TOS , act.actionType());
@@ -330,7 +330,7 @@
@Test
public void testSetActionSetTcpUdpSrcPortActionSetTcpUdpPort(){
FlowEntryAction act = new FlowEntryAction();
- ActionSetTcpUdpPort setPorts = act.new ActionSetTcpUdpPort((short)42);
+ ActionSetTcpUdpPort setPorts = new FlowEntryAction.ActionSetTcpUdpPort((short)42);
act.setActionSetTcpUdpSrcPort( setPorts );
assertEquals("action type",FlowEntryAction.ActionValues.ACTION_SET_TP_SRC , act.actionType());
@@ -362,7 +362,7 @@
@Test
public void testSetActionSetTcpUdpDstPortActionSetTcpUdpPort(){
FlowEntryAction act = new FlowEntryAction();
- ActionSetTcpUdpPort setPorts = act.new ActionSetTcpUdpPort((short)42);
+ ActionSetTcpUdpPort setPorts = new FlowEntryAction.ActionSetTcpUdpPort((short)42);
act.setActionSetTcpUdpDstPort( setPorts );
assertEquals("action type",FlowEntryAction.ActionValues.ACTION_SET_TP_DST , act.actionType());
@@ -394,7 +394,7 @@
@Test
public void testSetActionEnqueueActionEnqueue(){
FlowEntryAction act = new FlowEntryAction();
- ActionEnqueue enq = act.new ActionEnqueue(new Port((short)42), 1);
+ ActionEnqueue enq = new FlowEntryAction.ActionEnqueue(new Port((short)42), 1);
act.setActionEnqueue( enq );
assertEquals("action type",FlowEntryAction.ActionValues.ACTION_ENQUEUE , act.actionType());