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/packet/ARP.java b/src/main/java/net/onrc/onos/core/packet/ARP.java
index e6fcecc..3b315f3 100644
--- a/src/main/java/net/onrc/onos/core/packet/ARP.java
+++ b/src/main/java/net/onrc/onos/core/packet/ARP.java
@@ -20,8 +20,6 @@
import java.nio.ByteBuffer;
import java.util.Arrays;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
-
/**
* @author David Erickson (daviderickson@cs.stanford.edu)
*/
@@ -123,38 +121,44 @@
/**
* @return the senderHardwareAddress
*/
- @SuppressFBWarnings(value = "EI_EXPOSE_REP",
- justification = "TODO: Return a copy of the object?")
public byte[] getSenderHardwareAddress() {
- return senderHardwareAddress;
+ if (this.senderHardwareAddress == null) {
+ return null;
+ }
+ return this.senderHardwareAddress.clone();
}
/**
* @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;
+ if (senderHardwareAddress == null) {
+ this.senderHardwareAddress = null;
+ } else {
+ this.senderHardwareAddress = senderHardwareAddress.clone();
+ }
return this;
}
/**
* @return the senderProtocolAddress
*/
- @SuppressFBWarnings(value = "EI_EXPOSE_REP",
- justification = "TODO: Return a copy of the object?")
public byte[] getSenderProtocolAddress() {
- return senderProtocolAddress;
+ if (this.senderProtocolAddress == null) {
+ return null;
+ }
+ return this.senderProtocolAddress.clone();
}
/**
* @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;
+ if (senderProtocolAddress == null) {
+ this.senderProtocolAddress = null;
+ } else {
+ this.senderProtocolAddress = senderProtocolAddress.clone();
+ }
return this;
}
@@ -166,29 +170,33 @@
/**
* @return the targetHardwareAddress
*/
- @SuppressFBWarnings(value = "EI_EXPOSE_REP",
- justification = "TODO: Return a copy of the object?")
public byte[] getTargetHardwareAddress() {
- return targetHardwareAddress;
+ if (this.targetHardwareAddress == null) {
+ return null;
+ }
+ return this.targetHardwareAddress.clone();
}
/**
* @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;
+ if (targetHardwareAddress == null) {
+ this.targetHardwareAddress = null;
+ } else {
+ this.targetHardwareAddress = targetHardwareAddress.clone();
+ }
return this;
}
/**
* @return the targetProtocolAddress
*/
- @SuppressFBWarnings(value = "EI_EXPOSE_REP",
- justification = "TODO: Return a copy of the object?")
public byte[] getTargetProtocolAddress() {
- return targetProtocolAddress;
+ if (this.targetProtocolAddress == null) {
+ return null;
+ }
+ return this.targetProtocolAddress.clone();
}
/**
@@ -211,10 +219,12 @@
/**
* @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;
+ if (targetProtocolAddress == null) {
+ this.targetProtocolAddress = null;
+ } else {
+ this.targetProtocolAddress = targetProtocolAddress.clone();
+ }
return this;
}