import com.google.common.base.Preconditions;
import com.google.common.primitives.UnsignedBytes;
-import java.util.Arrays;
import org.opendaylight.protocol.util.Values;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger LOG = LoggerFactory.getLogger(BGPDocumentedException.class);
+ private static final byte[] EMPTY = new byte[0];
+
private final BGPError error;
private final byte[] data;
public BGPDocumentedException(final String message, final BGPError error, final byte[] data, final Exception cause) {
super(message, cause);
this.error = error;
- this.data = data == null ? null : Arrays.copyOf(data, data.length);
+ this.data = data == null || data.length == 0 ? null : data.clone();
LOG.error("Error = {}", error, this);
}
* @return documented error
*/
public BGPError getError() {
- return this.error;
+ return error;
}
/**
* @return byte array data
*/
public byte[] getData() {
- return (this.data != null) ? Arrays.copyOf(this.data, this.data.length) : new byte[0];
+ return data != null ? data.clone() : EMPTY;
}
public static BGPDocumentedException badMessageLength(final String message, final int length) {
return new BGPDocumentedException(message, BGPError.BAD_MSG_LENGTH, new byte[] {
UnsignedBytes.checkedCast(length / (Values.UNSIGNED_BYTE_MAX_VALUE + 1)),
UnsignedBytes.checkedCast(length % (Values.UNSIGNED_BYTE_MAX_VALUE + 1)) });
-
}
}