This is an automated email from the ASF dual-hosted git repository.
kturner pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/accumulo-access.git
The following commit(s) were added to refs/heads/main by this push:
new 2c05dfc use Objects bounds checking methods (#80)
2c05dfc is described below
commit 2c05dfcdf1b2eb5af30477258fc82c360ccf96a0
Author: Keith Turner <[email protected]>
AuthorDate: Fri Jul 26 08:27:08 2024 -0700
use Objects bounds checking methods (#80)
Co-authored-by: Christopher Tubbs <[email protected]>
---
.../org/apache/accumulo/access/BytesWrapper.java | 32 +++++-----------------
1 file changed, 7 insertions(+), 25 deletions(-)
diff --git a/src/main/java/org/apache/accumulo/access/BytesWrapper.java
b/src/main/java/org/apache/accumulo/access/BytesWrapper.java
index 069a66f..db6d48d 100644
--- a/src/main/java/org/apache/accumulo/access/BytesWrapper.java
+++ b/src/main/java/org/apache/accumulo/access/BytesWrapper.java
@@ -19,14 +19,16 @@
package org.apache.accumulo.access;
import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.Objects.checkFromIndexSize;
+import static java.util.Objects.checkIndex;
import java.util.Arrays;
final class BytesWrapper implements Comparable<BytesWrapper> {
- protected byte[] data;
- protected int offset;
- protected int length;
+ private byte[] data;
+ private int offset;
+ private int length;
/**
* Creates a new sequence. The given byte array is used directly as the
backing array, so later
@@ -54,16 +56,7 @@ final class BytesWrapper implements Comparable<BytesWrapper>
{
}
byte byteAt(int i) {
-
- if (i < 0) {
- throw new IllegalArgumentException("i < 0, " + i);
- }
-
- if (i >= length) {
- throw new IllegalArgumentException("i >= length, " + i + " >= " +
length);
- }
-
- return data[offset + i];
+ return data[offset + checkIndex(i, length)];
}
public int length() {
@@ -118,18 +111,7 @@ final class BytesWrapper implements
Comparable<BytesWrapper> {
* a copy of the input buffer
*/
void set(byte[] data, int offset, int length) {
- if (offset < 0) {
- throw new IllegalArgumentException("Offset cannot be negative. length =
" + offset);
- }
- if (length < 0) {
- throw new IllegalArgumentException("Length cannot be negative. length =
" + length);
- }
- if ((offset + length) > data.length) {
- throw new IllegalArgumentException(
- "Sum of offset and length exceeds data length. data.length = " +
data.length
- + ", offset = " + offset + ", length = " + length);
- }
-
+ checkFromIndexSize(offset, length, data.length);
this.data = data;
this.offset = offset;
this.length = length;