Suppress issues found by FindBugs: EI_EXPOSE_REP and EI_EXPOSE_REP2

http://findbugs.sourceforge.net/bugDescriptions.html#EI_EXPOSE_REP

http://findbugs.sourceforge.net/bugDescriptions.html#EI_EXPOSE_REP2

A proper fix for EI_EXPOSE_REP would require eventually to return a copy of an
internal object.
A proper fix for EI_EXPOSE_REP2 would require eventually to store a copy of the
provided object-argument.
However, the performance implication of creating the extra copies is not clear,
hence for the time being all those issues are suppressed by using the following
statements:

    @SuppressFBWarnings(value = "EI_EXPOSE_REP",
                        justification = "TODO: Return a copy of the object?")

    @SuppressFBWarnings(value = "EI_EXPOSE_REP2",
                        justification = "TODO: Store a copy of the object?")

Those suppressed warnings should be re-evaluated and addressed on case-by-case, e.g.
create object copies as appropriate.

Change-Id: I2df00242876e6c185d9fc098b15217138a324a8d
diff --git a/src/main/java/net/onrc/onos/core/datastore/hazelcast/HZMultiEntryOperation.java b/src/main/java/net/onrc/onos/core/datastore/hazelcast/HZMultiEntryOperation.java
index db354eb..0a7fc5e 100644
--- a/src/main/java/net/onrc/onos/core/datastore/hazelcast/HZMultiEntryOperation.java
+++ b/src/main/java/net/onrc/onos/core/datastore/hazelcast/HZMultiEntryOperation.java
@@ -4,6 +4,8 @@
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
 import net.onrc.onos.core.datastore.IKVTableID;
 import net.onrc.onos.core.datastore.IMultiEntryOperation;
 import net.onrc.onos.core.datastore.hazelcast.HZTable.VersionedValue;
@@ -33,6 +35,8 @@
      * @param key
      * @param operation
      */
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP2",
+                        justification = "TODO: Store a copy of the object?")
     public HZMultiEntryOperation(final HZTable table, final byte[] key, final OPERATION operation) {
         this.table = table;
         this.key = key;
@@ -52,6 +56,8 @@
      * @param version
      * @param operation
      */
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP2",
+                        justification = "TODO: Store a copy of the object?")
     public HZMultiEntryOperation(final HZTable table, final byte[] key, final byte[] value, final long version, final OPERATION operation) {
         this.table = table;
         this.key = key;
@@ -81,6 +87,8 @@
     }
 
     @Override
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP",
+                        justification = "TODO: Return a copy of the object?")
     public byte[] getKey() {
         return key;
     }
diff --git a/src/main/java/net/onrc/onos/core/datastore/hazelcast/HZTable.java b/src/main/java/net/onrc/onos/core/datastore/hazelcast/HZTable.java
index 20501bb..e609bce 100644
--- a/src/main/java/net/onrc/onos/core/datastore/hazelcast/HZTable.java
+++ b/src/main/java/net/onrc/onos/core/datastore/hazelcast/HZTable.java
@@ -7,6 +7,8 @@
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicLong;
 
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
 import net.onrc.onos.core.datastore.IKVTable;
 import net.onrc.onos.core.datastore.IKVTableID;
 import net.onrc.onos.core.datastore.ObjectDoesntExistException;
@@ -152,6 +154,8 @@
         byte[] value;
         long version;
 
+        @SuppressFBWarnings(value = "EI_EXPOSE_REP2",
+                            justification = "TODO: Store a copy of the object?")
         public Entry(final byte[] key, final byte[] value, final long version) {
             this.key = key;
             this.setValue(value);
@@ -163,11 +167,15 @@
         }
 
         @Override
+        @SuppressFBWarnings(value = "EI_EXPOSE_REP",
+                            justification = "TODO: Return a copy of the object?")
         public byte[] getKey() {
             return key;
         }
 
         @Override
+        @SuppressFBWarnings(value = "EI_EXPOSE_REP",
+                            justification = "TODO: Return a copy of the object?")
         public byte[] getValue() {
             return value;
         }
diff --git a/src/main/java/net/onrc/onos/core/datastore/ramcloud/RCTable.java b/src/main/java/net/onrc/onos/core/datastore/ramcloud/RCTable.java
index 3c78cf1..5ce07a4 100644
--- a/src/main/java/net/onrc/onos/core/datastore/ramcloud/RCTable.java
+++ b/src/main/java/net/onrc/onos/core/datastore/ramcloud/RCTable.java
@@ -1,5 +1,7 @@
 package net.onrc.onos.core.datastore.ramcloud;
 
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
 import net.onrc.onos.core.datastore.IKVTable;
 import net.onrc.onos.core.datastore.IKVTableID;
 import net.onrc.onos.core.datastore.ObjectDoesntExistException;
@@ -21,6 +23,8 @@
         byte[] value;
         long version;
 
+        @SuppressFBWarnings(value = "EI_EXPOSE_REP2",
+                            justification = "TODO: Store a copy of the object?")
         public Entry(final byte[] key, final byte[] value, final long version) {
             this.key = key;
             this.setValue(value);
@@ -32,11 +36,15 @@
         }
 
         @Override
+        @SuppressFBWarnings(value = "EI_EXPOSE_REP",
+                            justification = "TODO: Return a copy of the object?")
         public byte[] getKey() {
             return key;
         }
 
         @Override
+        @SuppressFBWarnings(value = "EI_EXPOSE_REP",
+                            justification = "TODO: Return a copy of the object?")
         public byte[] getValue() {
             return value;
         }
diff --git a/src/main/java/net/onrc/onos/core/datastore/topology/KVDevice.java b/src/main/java/net/onrc/onos/core/datastore/topology/KVDevice.java
index 4b9d3c3..3c56d2c 100644
--- a/src/main/java/net/onrc/onos/core/datastore/topology/KVDevice.java
+++ b/src/main/java/net/onrc/onos/core/datastore/topology/KVDevice.java
@@ -10,6 +10,8 @@
 import java.util.Set;
 import java.util.TreeSet;
 
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
 import net.onrc.onos.core.datastore.DataStoreClient;
 import net.onrc.onos.core.datastore.IKVTable.IKVEntry;
 import net.onrc.onos.core.datastore.topology.KVLink.STATUS;
@@ -75,6 +77,8 @@
         return mac;
     }
 
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP2",
+                        justification = "TODO: Store a copy of the object?")
     public KVDevice(final byte[] mac) {
         super(DataStoreClient.getClient().getTable(GLOBAL_DEVICE_TABLE_NAME), getDeviceID(mac));
 
@@ -121,6 +125,8 @@
         }
     }
 
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP",
+                        justification = "TODO: Return a copy of the object?")
     public byte[] getMac() {
         // TODO may need to clone() to be sure this object will be immutable.
         return mac;
diff --git a/src/main/java/net/onrc/onos/core/datastore/utils/KVObject.java b/src/main/java/net/onrc/onos/core/datastore/utils/KVObject.java
index 618c31e..078c82d 100644
--- a/src/main/java/net/onrc/onos/core/datastore/utils/KVObject.java
+++ b/src/main/java/net/onrc/onos/core/datastore/utils/KVObject.java
@@ -6,6 +6,8 @@
 import java.util.List;
 import java.util.Map;
 
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
 import net.onrc.onos.core.datastore.DataStoreClient;
 import net.onrc.onos.core.datastore.IKVClient;
 import net.onrc.onos.core.datastore.IKVTable;
@@ -62,6 +64,8 @@
         this(table, key, null, table.getVersionNonexistant());
     }
 
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP2",
+                        justification = "TODO: Store a copy of the object?")
     public KVObject(final IKVTable table, final byte[] key, final byte[] value, final long version) {
         if (table == null) {
             throw new IllegalArgumentException("table cannot be null");
@@ -93,6 +97,8 @@
         return table.getTableId();
     }
 
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP",
+                        justification = "TODO: Return a copy of the object?")
     public byte[] getKey() {
         return key;
     }
diff --git a/src/main/java/net/onrc/onos/core/devicemanager/OnosDevice.java b/src/main/java/net/onrc/onos/core/devicemanager/OnosDevice.java
index 157d52f..f047b38 100644
--- a/src/main/java/net/onrc/onos/core/devicemanager/OnosDevice.java
+++ b/src/main/java/net/onrc/onos/core/devicemanager/OnosDevice.java
@@ -20,6 +20,8 @@
 import java.io.Serializable;
 import java.util.Date;
 
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
 import net.floodlightcontroller.util.MACAddress;
 import net.onrc.onos.core.packet.IPv4;
 
@@ -93,6 +95,8 @@
      * @param switchPort
      * @param lastSeenTimestamp
      */
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP2",
+                        justification = "TODO: Store a copy of the object?")
     public OnosDevice(MACAddress macAddress, Short vlan,
                       Integer ipv4Address, Long switchDPID, short switchPort,
                       Date lastSeenTimestamp) {
@@ -141,11 +145,14 @@
         this.switchPort = port;
     }
 
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP",
+                        justification = "TODO: Return a copy of the object?")
     public Date getLastSeenTimestamp() {
         return lastSeenTimestamp;
     }
 
-
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP2",
+                        justification = "TODO: Store a copy of the object?")
     public void setLastSeenTimestamp(Date lastSeenTimestamp) {
         if (activeSince == null ||
                 (activeSince.getTime() + ACTIVITY_TIMEOUT) <
@@ -155,10 +162,14 @@
         this.lastSeenTimestamp = lastSeenTimestamp;
     }
 
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP",
+                        justification = "TODO: Return a copy of the object?")
     public Date getActiveSince() {
         return activeSince;
     }
 
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP2",
+                        justification = "TODO: Store a copy of the object?")
     public void setActiveSince(Date activeSince) {
         this.activeSince = activeSince;
     }
diff --git a/src/main/java/net/onrc/onos/core/packet/ARP.java b/src/main/java/net/onrc/onos/core/packet/ARP.java
index ae49c4b..e6fcecc 100644
--- a/src/main/java/net/onrc/onos/core/packet/ARP.java
+++ b/src/main/java/net/onrc/onos/core/packet/ARP.java
@@ -20,6 +20,8 @@
 import java.nio.ByteBuffer;
 import java.util.Arrays;
 
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
 /**
  * @author David Erickson (daviderickson@cs.stanford.edu)
  */
@@ -121,6 +123,8 @@
     /**
      * @return the senderHardwareAddress
      */
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP",
+                        justification = "TODO: Return a copy of the object?")
     public byte[] getSenderHardwareAddress() {
         return senderHardwareAddress;
     }
@@ -128,6 +132,8 @@
     /**
      * @param senderHardwareAddress the senderHardwareAddress to set
      */
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP2",
+                        justification = "TODO: Store a copy of the object?")
     public ARP setSenderHardwareAddress(byte[] senderHardwareAddress) {
         this.senderHardwareAddress = senderHardwareAddress;
         return this;
@@ -136,6 +142,8 @@
     /**
      * @return the senderProtocolAddress
      */
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP",
+                        justification = "TODO: Return a copy of the object?")
     public byte[] getSenderProtocolAddress() {
         return senderProtocolAddress;
     }
@@ -143,6 +151,8 @@
     /**
      * @param senderProtocolAddress the senderProtocolAddress to set
      */
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP2",
+                        justification = "TODO: Store a copy of the object?")
     public ARP setSenderProtocolAddress(byte[] senderProtocolAddress) {
         this.senderProtocolAddress = senderProtocolAddress;
         return this;
@@ -156,6 +166,8 @@
     /**
      * @return the targetHardwareAddress
      */
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP",
+                        justification = "TODO: Return a copy of the object?")
     public byte[] getTargetHardwareAddress() {
         return targetHardwareAddress;
     }
@@ -163,6 +175,8 @@
     /**
      * @param targetHardwareAddress the targetHardwareAddress to set
      */
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP2",
+                        justification = "TODO: Store a copy of the object?")
     public ARP setTargetHardwareAddress(byte[] targetHardwareAddress) {
         this.targetHardwareAddress = targetHardwareAddress;
         return this;
@@ -171,6 +185,8 @@
     /**
      * @return the targetProtocolAddress
      */
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP",
+                        justification = "TODO: Return a copy of the object?")
     public byte[] getTargetProtocolAddress() {
         return targetProtocolAddress;
     }
@@ -195,6 +211,8 @@
     /**
      * @param targetProtocolAddress the targetProtocolAddress to set
      */
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP2",
+                        justification = "TODO: Store a copy of the object?")
     public ARP setTargetProtocolAddress(byte[] targetProtocolAddress) {
         this.targetProtocolAddress = targetProtocolAddress;
         return this;
diff --git a/src/main/java/net/onrc/onos/core/packet/BSNPROBE.java b/src/main/java/net/onrc/onos/core/packet/BSNPROBE.java
index 2f19d49..e8eed9e 100644
--- a/src/main/java/net/onrc/onos/core/packet/BSNPROBE.java
+++ b/src/main/java/net/onrc/onos/core/packet/BSNPROBE.java
@@ -22,6 +22,8 @@
 import java.nio.ByteBuffer;
 import java.util.Arrays;
 
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
 import org.openflow.util.HexString;
 
 /**
@@ -59,19 +61,27 @@
         return this;
     }
 
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP",
+                        justification = "TODO: Return a copy of the object?")
     public byte[] getSrcMac() {
         return this.srcMac;
     }
 
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP2",
+                        justification = "TODO: Store a copy of the object?")
     public BSNPROBE setSrcMac(byte[] srcMac) {
         this.srcMac = srcMac;
         return this;
     }
 
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP",
+                        justification = "TODO: Return a copy of the object?")
     public byte[] getDstMac() {
         return dstMac;
     }
 
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP2",
+                        justification = "TODO: Store a copy of the object?")
     public BSNPROBE setDstMac(byte[] dstMac) {
         this.dstMac = dstMac;
         return this;
diff --git a/src/main/java/net/onrc/onos/core/packet/DHCP.java b/src/main/java/net/onrc/onos/core/packet/DHCP.java
index e2a109e..9322672 100644
--- a/src/main/java/net/onrc/onos/core/packet/DHCP.java
+++ b/src/main/java/net/onrc/onos/core/packet/DHCP.java
@@ -23,6 +23,8 @@
 import java.util.List;
 import java.util.ListIterator;
 
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
 /**
  * @author David Erickson (daviderickson@cs.stanford.edu)
  */
@@ -267,6 +269,8 @@
     /**
      * @return the clientHardwareAddress
      */
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP",
+                        justification = "TODO: Return a copy of the object?")
     public byte[] getClientHardwareAddress() {
         return clientHardwareAddress;
     }
@@ -274,6 +278,8 @@
     /**
      * @param clientHardwareAddress the clientHardwareAddress to set
      */
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP2",
+                        justification = "TODO: Store a copy of the object?")
     public DHCP setClientHardwareAddress(byte[] clientHardwareAddress) {
         this.clientHardwareAddress = clientHardwareAddress;
         return this;
diff --git a/src/main/java/net/onrc/onos/core/packet/DHCPOption.java b/src/main/java/net/onrc/onos/core/packet/DHCPOption.java
index e2b3c00..81bbed4 100644
--- a/src/main/java/net/onrc/onos/core/packet/DHCPOption.java
+++ b/src/main/java/net/onrc/onos/core/packet/DHCPOption.java
@@ -19,6 +19,8 @@
 
 import java.util.Arrays;
 
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
 /**
  * @author David Erickson (daviderickson@cs.stanford.edu)
  */
@@ -60,6 +62,8 @@
     /**
      * @return the data
      */
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP",
+                        justification = "TODO: Return a copy of the object?")
     public byte[] getData() {
         return data;
     }
@@ -67,6 +71,8 @@
     /**
      * @param data the data to set
      */
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP2",
+                        justification = "TODO: Store a copy of the object?")
     public DHCPOption setData(byte[] data) {
         this.data = data;
         return this;
diff --git a/src/main/java/net/onrc/onos/core/packet/Data.java b/src/main/java/net/onrc/onos/core/packet/Data.java
index a2e7a79..6701965 100644
--- a/src/main/java/net/onrc/onos/core/packet/Data.java
+++ b/src/main/java/net/onrc/onos/core/packet/Data.java
@@ -19,6 +19,8 @@
 
 import java.util.Arrays;
 
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
 /**
  * @author David Erickson (daviderickson@cs.stanford.edu)
  */
@@ -34,6 +36,8 @@
     /**
      * @param data
      */
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP2",
+                        justification = "TODO: Store a copy of the object?")
     public Data(byte[] data) {
         this.data = data;
     }
@@ -41,6 +45,8 @@
     /**
      * @return the data
      */
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP",
+                        justification = "TODO: Return a copy of the object?")
     public byte[] getData() {
         return data;
     }
@@ -48,11 +54,15 @@
     /**
      * @param data the data to set
      */
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP2",
+                        justification = "TODO: Store a copy of the object?")
     public Data setData(byte[] data) {
         this.data = data;
         return this;
     }
 
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP",
+                        justification = "TODO: Return a copy of the object?")
     public byte[] serialize() {
         return this.data;
     }
diff --git a/src/main/java/net/onrc/onos/core/packet/IPv4.java b/src/main/java/net/onrc/onos/core/packet/IPv4.java
index 72efa61..ed7d9dc 100644
--- a/src/main/java/net/onrc/onos/core/packet/IPv4.java
+++ b/src/main/java/net/onrc/onos/core/packet/IPv4.java
@@ -26,6 +26,8 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
 /**
  * @author David Erickson (daviderickson@cs.stanford.edu)
  */
@@ -265,6 +267,8 @@
     /**
      * @return the options
      */
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP",
+                        justification = "TODO: Return a copy of the object?")
     public byte[] getOptions() {
         return options;
     }
@@ -272,6 +276,8 @@
     /**
      * @param options the options to set
      */
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP2",
+                        justification = "TODO: Store a copy of the object?")
     public IPv4 setOptions(byte[] options) {
         if (options != null && (options.length % 4) > 0) {
             throw new IllegalArgumentException(
diff --git a/src/main/java/net/onrc/onos/core/packet/LLDPTLV.java b/src/main/java/net/onrc/onos/core/packet/LLDPTLV.java
index 402a508..7acef72 100644
--- a/src/main/java/net/onrc/onos/core/packet/LLDPTLV.java
+++ b/src/main/java/net/onrc/onos/core/packet/LLDPTLV.java
@@ -20,6 +20,8 @@
 import java.nio.ByteBuffer;
 import java.util.Arrays;
 
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
 /**
  * @author David Erickson (daviderickson@cs.stanford.edu)
  */
@@ -61,6 +63,8 @@
     /**
      * @return the value
      */
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP",
+                        justification = "TODO: Return a copy of the object?")
     public byte[] getValue() {
         return value;
     }
@@ -68,6 +72,8 @@
     /**
      * @param value the value to set
      */
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP2",
+                        justification = "TODO: Store a copy of the object?")
     public LLDPTLV setValue(byte[] value) {
         this.value = value;
         return this;
diff --git a/src/main/java/net/onrc/onos/core/packet/TCP.java b/src/main/java/net/onrc/onos/core/packet/TCP.java
index f2f49e1..b435d74 100644
--- a/src/main/java/net/onrc/onos/core/packet/TCP.java
+++ b/src/main/java/net/onrc/onos/core/packet/TCP.java
@@ -20,6 +20,8 @@
 import java.nio.ByteBuffer;
 import java.util.Arrays;
 
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
 /**
  * @author shudong.zhou@bigswitch.com
  */
@@ -141,11 +143,15 @@
         return this;
     }
 
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP",
+                        justification = "TODO: Return a copy of the object?")
     public byte[] getOptions() {
         return this.options;
     }
 
-    public TCP setOptions(byte[] options) {
+    @SuppressFBWarnings(value = "EI_EXPOSE_REP2",
+                        justification = "TODO: Store a copy of the object?")
+    public TCP setOptions(final byte[] options) {
         this.options = options;
         this.dataOffset = (byte) ((20 + options.length + 3) >> 2);
         return this;