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/IPv4.java b/src/main/java/net/onrc/onos/core/packet/IPv4.java
index fbb91ab..f105428 100644
--- a/src/main/java/net/onrc/onos/core/packet/IPv4.java
+++ b/src/main/java/net/onrc/onos/core/packet/IPv4.java
@@ -26,6 +26,8 @@
import java.util.HashMap;
import java.util.Map;
+import org.apache.commons.lang.ArrayUtils;
+
/**
* @author David Erickson (daviderickson@cs.stanford.edu)
*/
@@ -266,10 +268,7 @@
* @return the options
*/
public byte[] getOptions() {
- if (this.options == null) {
- return null;
- }
- return this.options.clone();
+ return ArrayUtils.clone(this.options);
}
/**
@@ -280,11 +279,7 @@
throw new IllegalArgumentException(
"Options length must be a multiple of 4");
}
- if (options == null) {
- this.options = null;
- } else {
- this.options = options.clone();
- }
+ this.options = ArrayUtils.clone(options);
return this;
}