Fix EI_EXPOSE_REP family issue by copying.
Note: Variables which may be valid to be null uses ArrayUtils.clone()
Change-Id: I6a13dfd66753847de306d50bbdf32e724d896c56
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 d3df22c..99db3cc 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,8 +4,6 @@
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;
@@ -35,11 +33,9 @@
* @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;
+ this.key = key.clone();
this.status = STATUS.NOT_EXECUTED;
this.operation = operation;
@@ -56,11 +52,9 @@
* @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;
+ this.key = key.clone();
this.status = STATUS.NOT_EXECUTED;
this.operation = operation;
@@ -87,10 +81,8 @@
}
@Override
- @SuppressFBWarnings(value = "EI_EXPOSE_REP",
- justification = "TODO: Return a copy of the object?")
public byte[] getKey() {
- return key;
+ return key.clone();
}
@Override
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 e609bce..c83e45d 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,14 +7,13 @@
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;
import net.onrc.onos.core.datastore.ObjectExistsException;
import net.onrc.onos.core.datastore.WrongVersionException;
+import org.apache.commons.lang.ArrayUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -70,7 +69,7 @@
}
public VersionedValue(final byte[] value, final long version) {
- this.value = value;
+ this.value = ArrayUtils.clone(value);
this.version = version;
}
@@ -83,7 +82,7 @@
}
public void setValue(final byte[] value) {
- this.value = value;
+ this.value = ArrayUtils.clone(value);
}
public void setNextVersion() {
@@ -154,10 +153,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.key = key.clone();
this.setValue(value);
this.setVersion(version);
}
@@ -167,17 +164,13 @@
}
@Override
- @SuppressFBWarnings(value = "EI_EXPOSE_REP",
- justification = "TODO: Return a copy of the object?")
public byte[] getKey() {
- return key;
+ return key.clone();
}
@Override
- @SuppressFBWarnings(value = "EI_EXPOSE_REP",
- justification = "TODO: Return a copy of the object?")
public byte[] getValue() {
- return value;
+ return ArrayUtils.clone(value);
}
@Override
@@ -186,7 +179,7 @@
}
void setValue(final byte[] value) {
- this.value = value;
+ this.value = ArrayUtils.clone(value);
}
void setVersion(final long version) {
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 5ce07a4..4a92b4f 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,13 +1,12 @@
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;
import net.onrc.onos.core.datastore.ObjectExistsException;
import net.onrc.onos.core.datastore.WrongVersionException;
+import org.apache.commons.lang.ArrayUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -23,10 +22,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.key = key.clone();
this.setValue(value);
this.setVersion(version);
}
@@ -36,17 +33,13 @@
}
@Override
- @SuppressFBWarnings(value = "EI_EXPOSE_REP",
- justification = "TODO: Return a copy of the object?")
public byte[] getKey() {
- return key;
+ return key.clone();
}
@Override
- @SuppressFBWarnings(value = "EI_EXPOSE_REP",
- justification = "TODO: Return a copy of the object?")
public byte[] getValue() {
- return value;
+ return ArrayUtils.clone(value);
}
@Override
@@ -55,7 +48,7 @@
}
void setValue(byte[] value) {
- this.value = value;
+ this.value = ArrayUtils.clone(value);
}
void setVersion(long version) {
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 3c56d2c..9a6d550 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,8 +10,6 @@
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;
@@ -77,12 +75,10 @@
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));
- this.mac = mac;
+ this.mac = mac.clone();
this.portIds = new TreeSet<>(ByteArrayComparator.BYTEARRAY_COMPARATOR);
this.isPortIdsModified = true;
}
@@ -125,11 +121,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;
+ return mac.clone();
}
public byte[] getId() {
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 078c82d..94f509f 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,8 +6,6 @@
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;
@@ -64,8 +62,6 @@
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");
@@ -74,7 +70,7 @@
throw new IllegalArgumentException("key cannot be null");
}
this.table = table;
- this.key = key;
+ this.key = key.clone();
this.version = version;
this.propertyMap = new HashMap<Object, Object>();
@@ -97,10 +93,8 @@
return table.getTableId();
}
- @SuppressFBWarnings(value = "EI_EXPOSE_REP",
- justification = "TODO: Return a copy of the object?")
public byte[] getKey() {
- return key;
+ return key.clone();
}
public long getVersion() {