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/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) {