Fix some of the suppressed FindBugs warnings: EI_EXPOSE_REP and EI_EXPOSE_REP2

The fix is to copy the data when setting/returning it.
If this becomes a bottleneck, we can revisit the solution.


Change-Id: I7ad345aa8d19a41221b3550dd9d2cfcd08b36fd1
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 f047b38..796129a 100644
--- a/src/main/java/net/onrc/onos/core/devicemanager/OnosDevice.java
+++ b/src/main/java/net/onrc/onos/core/devicemanager/OnosDevice.java
@@ -20,8 +20,6 @@
 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;
 
@@ -95,8 +93,6 @@
      * @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) {
@@ -105,8 +101,13 @@
         this.vlan = vlan;
         this.switchDPID = switchDPID;
         this.switchPort = switchPort;
-        this.lastSeenTimestamp = lastSeenTimestamp;
-        this.activeSince = lastSeenTimestamp;
+        if (lastSeenTimestamp != null) {
+            this.lastSeenTimestamp = new Date(lastSeenTimestamp.getTime());
+            this.activeSince = new Date(lastSeenTimestamp.getTime());
+        } else {
+            this.lastSeenTimestamp = null;
+            this.activeSince = null;
+        }
     }
 
     // ***************
@@ -145,33 +146,28 @@
         this.switchPort = port;
     }
 
-    @SuppressFBWarnings(value = "EI_EXPOSE_REP",
-                        justification = "TODO: Return a copy of the object?")
     public Date getLastSeenTimestamp() {
-        return lastSeenTimestamp;
+        if (this.lastSeenTimestamp == null) {
+            return null;
+        }
+        return new Date(this.lastSeenTimestamp.getTime());
     }
 
-    @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) <
                         lastSeenTimestamp.getTime()) {
-            this.activeSince = lastSeenTimestamp;
+            this.activeSince = new Date(lastSeenTimestamp.getTime());
         }
-        this.lastSeenTimestamp = lastSeenTimestamp;
+        this.lastSeenTimestamp = new Date(lastSeenTimestamp.getTime());
     }
 
-    @SuppressFBWarnings(value = "EI_EXPOSE_REP",
-                        justification = "TODO: Return a copy of the object?")
     public Date getActiveSince() {
-        return activeSince;
+        return new Date(this.activeSince.getTime());
     }
 
-    @SuppressFBWarnings(value = "EI_EXPOSE_REP2",
-                        justification = "TODO: Store a copy of the object?")
     public void setActiveSince(Date activeSince) {
-        this.activeSince = activeSince;
+        this.activeSince = new Date(activeSince.getTime());
     }
 
     @Override