Use ArrayUtils.clone() to clone byte[] arrays.
Using ArrayUtils.clone() simplifies the code, because it handles
null arrays.
Change-Id: I434856c5a9713759a642dd32a7ca8dfafb136047
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 def194c..6b6c355 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 org.apache.commons.lang.ArrayUtils;
+
/**
* @author shudong.zhou@bigswitch.com
*/
@@ -142,19 +144,15 @@
}
public byte[] getOptions() {
- if (this.options == null) {
- return null;
- }
- return this.options.clone();
+ return ArrayUtils.clone(this.options);
}
public TCP setOptions(final byte[] options) {
- if (options == null) {
- this.options = null;
+ this.options = ArrayUtils.clone(options);
+ if (this.options == null) {
this.dataOffset = 0;
} else {
- this.options = options.clone();
- this.dataOffset = (byte) ((20 + options.length + 3) >> 2);
+ this.dataOffset = (byte) ((20 + this.options.length + 3) >> 2);
}
return this;
}