Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
upgrade error prone
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme committed Nov 14, 2020
1 parent a2d0228 commit fa65c18
Show file tree
Hide file tree
Showing 103 changed files with 665 additions and 222 deletions.
3 changes: 0 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,6 @@ allprojects {

dependencies {
errorprone 'com.google.errorprone:error_prone_core'
if (JavaVersion.current().isJava8()) {
errorproneJavac("com.google.errorprone:javac")
}
}

tasks.withType(AbstractArchiveTask) {
Expand Down
78 changes: 53 additions & 25 deletions bytes/src/main/java/org/apache/tuweni/bytes/Bytes.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ static Bytes wrap(byte[] value) {
* @param length The length of the resulting value.
* @return A {@link Bytes} value that expose the bytes of {@code value} from {@code offset} (inclusive) to
* {@code offset + length} (exclusive).
* @throws IndexOutOfBoundsException if {@code offset < 0 || (value.length > 0 && offset >=
* @throws IndexOutOfBoundsException if {@code offset < 0 || (value.length > 0 && offset >=
* value.length)}.
* @throws IllegalArgumentException if {@code length &lt; 0 || offset + length > value.length}.
* @throws IllegalArgumentException if {@code length < 0 || offset + length > value.length}.
*/
static Bytes wrap(byte[] value, int offset, int length) {
checkNotNull(value);
Expand Down Expand Up @@ -187,9 +187,9 @@ static Bytes wrapBuffer(Buffer buffer) {
* {@code wrapBuffer(buffer, i, 1).get(0) == buffer.getByte(i)}.
* @param size The size of the returned value.
* @return A {@link Bytes} value.
* @throws IndexOutOfBoundsException if {@code offset &lt; 0 || (buffer.length() > 0 && offset >=
* @throws IndexOutOfBoundsException if {@code offset < 0 || (buffer.length() > 0 && offset >=
* buffer.length())}.
* @throws IllegalArgumentException if {@code length &lt; 0 || offset + length > buffer.length()}.
* @throws IllegalArgumentException if {@code length < 0 || offset + length > buffer.length()}.
*/
static Bytes wrapBuffer(Buffer buffer, int offset, int size) {
checkNotNull(buffer);
Expand Down Expand Up @@ -227,9 +227,9 @@ static Bytes wrapByteBuf(ByteBuf byteBuf) {
* {@code wrapByteBuf(byteBuf, i, 1).get(0) == byteBuf.getByte(i)}.
* @param size The size of the returned value.
* @return A {@link Bytes} value.
* @throws IndexOutOfBoundsException if {@code offset &lt; 0 || (byteBuf.capacity() > 0 && offset >=
* @throws IndexOutOfBoundsException if {@code offset < 0 || (byteBuf.capacity() > 0 && offset >=
* byteBuf.capacity())}.
* @throws IllegalArgumentException if {@code length &lt; 0 || offset + length > byteBuf.capacity()}.
* @throws IllegalArgumentException if {@code length < 0 || offset + length > byteBuf.capacity()}.
*/
static Bytes wrapByteBuf(ByteBuf byteBuf, int offset, int size) {
checkNotNull(byteBuf);
Expand Down Expand Up @@ -267,9 +267,9 @@ static Bytes wrapByteBuffer(ByteBuffer byteBuffer) {
* {@code wrapByteBuffer(byteBuffer, i, 1).get(0) == byteBuffer.getByte(i)}.
* @param size The size of the returned value.
* @return A {@link Bytes} value.
* @throws IndexOutOfBoundsException if {@code offset &lt; 0 || (byteBuffer.limit() > 0 && offset >=
* @throws IndexOutOfBoundsException if {@code offset < 0 || (byteBuffer.limit() > 0 && offset >=
* byteBuf.limit())}.
* @throws IllegalArgumentException if {@code length &lt; 0 || offset + length > byteBuffer.limit()}.
* @throws IllegalArgumentException if {@code length < 0 || offset + length > byteBuffer.limit()}.
*/
static Bytes wrapByteBuffer(ByteBuffer byteBuffer, int offset, int size) {
checkNotNull(byteBuffer);
Expand Down Expand Up @@ -482,7 +482,7 @@ static Bytes fromHexStringLenient(CharSequence str) {
* with zeros.
* @return A value of size {@code destinationSize} corresponding to {@code str} potentially left-padded.
* @throws IllegalArgumentException if {@code str} does not correspond to a valid hexadecimal representation,
* represents more bytes than {@code destinationSize} or {@code destinationSize &lt; 0}.
* represents more bytes than {@code destinationSize} or {@code destinationSize < 0}.
*/
static Bytes fromHexStringLenient(CharSequence str, int destinationSize) {
checkNotNull(str);
Expand Down Expand Up @@ -520,7 +520,7 @@ static Bytes fromHexString(CharSequence str) {
* @throws IllegalArgumentException if {@code str} does correspond to a valid hexadecimal representation, or is of an
* odd length.
* @throws IllegalArgumentException if {@code str} does not correspond to a valid hexadecimal representation, or is of
* an odd length, or represents more bytes than {@code destinationSize} or {@code destinationSize &lt; 0}.
* an odd length, or represents more bytes than {@code destinationSize} or {@code destinationSize < 0}.
*/
static Bytes fromHexString(CharSequence str, int destinationSize) {
checkNotNull(str);
Expand Down Expand Up @@ -561,15 +561,20 @@ static Bytes random(int size, Random generator) {
return Bytes.wrap(array);
}

/** @return The number of bytes this value represents. */
/**
*
* Provides the number of bytes this value represents.
*
* @return The number of bytes this value represents.
*/
int size();

/**
* Retrieve a byte in this value.
*
* @param i The index of the byte to fetch within the value (0-indexed).
* @return The byte at index {@code i} in this value.
* @throws IndexOutOfBoundsException if {@code i &lt; 0} or {i &gt;= size()}.
* @throws IndexOutOfBoundsException if {@code i < 0} or {i >= size()}.
*/
byte get(int i);

Expand All @@ -578,7 +583,7 @@ static Bytes random(int size, Random generator) {
*
* @param i The index from which to get the int, which must less than or equal to {@code size() - 4}.
* @return An integer whose value is the 4 bytes from this value starting at index {@code i}.
* @throws IndexOutOfBoundsException if {@code i &lt; 0} or {@code i &gt; size() - 4}.
* @throws IndexOutOfBoundsException if {@code i < 0} or {@code i > size() - 4}.
*/
default int getInt(int i) {
return getInt(i, BIG_ENDIAN);
Expand All @@ -590,7 +595,7 @@ default int getInt(int i) {
* @param i The index from which to get the int, which must less than or equal to {@code size() - 4}.
* @param order The byte-order for decoding the integer.
* @return An integer whose value is the 4 bytes from this value starting at index {@code i}.
* @throws IndexOutOfBoundsException if {@code i &lt; 0} or {@code i &gt; size() - 4}.
* @throws IndexOutOfBoundsException if {@code i < 0} or {@code i > size() - 4}.
*/
default int getInt(int i, ByteOrder order) {
int size = size();
Expand Down Expand Up @@ -619,7 +624,7 @@ default int getInt(int i, ByteOrder order) {
* The value corresponding to interpreting these bytes as an integer.
*
* @return An value corresponding to this value interpreted as an integer.
* @throws IllegalArgumentException if {@code size() &gt; 4}.
* @throws IllegalArgumentException if {@code size() > 4}.
*/
default int toInt() {
return toInt(BIG_ENDIAN);
Expand All @@ -630,7 +635,7 @@ default int toInt() {
*
* @param order The byte-order for decoding the integer.
* @return An value corresponding to this value interpreted as an integer.
* @throws IllegalArgumentException if {@code size() &gt; 4}.
* @throws IllegalArgumentException if {@code size() > 4}.
*/
default int toInt(ByteOrder order) {
int size = size();
Expand Down Expand Up @@ -685,7 +690,7 @@ default boolean isEmpty() {
*
* @param i The index from which to get the long, which must less than or equal to {@code size() - 8}.
* @return A long whose value is the 8 bytes from this value starting at index {@code i}.
* @throws IndexOutOfBoundsException if {@code i &lt; 0} or {@code i &gt; size() - 8}.
* @throws IndexOutOfBoundsException if {@code i < 0} or {@code i > size() - 8}.
*/
default long getLong(int i) {
return getLong(i, BIG_ENDIAN);
Expand All @@ -697,7 +702,7 @@ default long getLong(int i) {
* @param i The index from which to get the long, which must less than or equal to {@code size() - 8}.
* @param order The byte-order for decoding the integer.
* @return A long whose value is the 8 bytes from this value starting at index {@code i}.
* @throws IndexOutOfBoundsException if {@code i &lt; 0} or {@code i &gt; size() - 8}.
* @throws IndexOutOfBoundsException if {@code i < 0} or {@code i > size() - 8}.
*/
default long getLong(int i, ByteOrder order) {
int size = size();
Expand Down Expand Up @@ -734,7 +739,7 @@ default long getLong(int i, ByteOrder order) {
* The value corresponding to interpreting these bytes as a long.
*
* @return An value corresponding to this value interpreted as a long.
* @throws IllegalArgumentException if {@code size() &gt; 8}.
* @throws IllegalArgumentException if {@code size() > 8}.
*/
default long toLong() {
return toLong(BIG_ENDIAN);
Expand All @@ -745,7 +750,7 @@ default long toLong() {
*
* @param order The byte-order for decoding the integer.
* @return An value corresponding to this value interpreted as a long.
* @throws IllegalArgumentException if {@code size() &gt; 8}.
* @throws IllegalArgumentException if {@code size() > 8}.
*/
default long toLong(ByteOrder order) {
int size = size();
Expand Down Expand Up @@ -882,6 +887,9 @@ default boolean hasLeadingZero() {
}

/**
* Provides the number of zero bits preceding the highest-order ("leftmost") one-bit, or {@code size() * 8} if all
* bits * are zero.
*
* @return The number of zero bits preceding the highest-order ("leftmost") one-bit, or {@code size() * 8} if all bits
* are zero.
*/
Expand All @@ -908,6 +916,8 @@ default boolean hasLeadingZeroByte() {
}

/**
* Provides the number of leading zero bytes of the value
*
* @return The number of leading zero bytes of the value.
*/
default int numberOfLeadingZeroBytes() {
Expand All @@ -921,6 +931,8 @@ default int numberOfLeadingZeroBytes() {
}

/**
* Provides the number of trailing zero bytes of the value.
*
* @return The number of trailing zero bytes of the value.
*/
default int numberOfTrailingZeroBytes() {
Expand All @@ -934,6 +946,9 @@ default int numberOfTrailingZeroBytes() {
}

/**
* Provides the number of bits following and including the highest-order ("leftmost") one-bit, or zero if all bits are
* zero.
*
* @return The number of bits following and including the highest-order ("leftmost") one-bit, or zero if all bits are
* zero.
*/
Expand Down Expand Up @@ -1206,7 +1221,7 @@ default <T extends MutableBytes> T shiftLeft(int distance, T result) {
*
* @param i The start index for the slice.
* @return A new value providing a view over the bytes from index {@code i} (included) to the end.
* @throws IndexOutOfBoundsException if {@code i &lt; 0}.
* @throws IndexOutOfBoundsException if {@code i < 0}.
*/
default Bytes slice(int i) {
if (i == 0) {
Expand All @@ -1231,8 +1246,8 @@ default Bytes slice(int i) {
* @param length The length of the resulting value.
* @return A new value providing a view over the bytes from index {@code i} (included) to {@code i + length}
* (excluded).
* @throws IllegalArgumentException if {@code length &lt; 0}.
* @throws IndexOutOfBoundsException if {@code i &lt; 0} or {i &gt;= size()} or {i + length &gt; size()} .
* @throws IllegalArgumentException if {@code length < 0}.
* @throws IndexOutOfBoundsException if {@code i < 0} or {i >= size()} or {i + length > size()} .
*/
Bytes slice(int i, int length);

Expand Down Expand Up @@ -1282,7 +1297,7 @@ default void copyTo(MutableBytes destination) {
* {@code destinationOffset} for the copied value.
* @param destinationOffset The offset in {@code destination} at which the copy starts.
* @throws IllegalArgumentException if the destination doesn't have enough room, that is if {@code
* this.size() &gt; (destination.size() - destinationOffset)}.
* this.size() > (destination.size() - destinationOffset)}.
*/
default void copyTo(MutableBytes destination, int destinationOffset) {
checkNotNull(destination);
Expand Down Expand Up @@ -1478,13 +1493,17 @@ default byte[] toArrayUnsafe() {
String toString();

/**
* Provides this value represented as hexadecimal, starting with "0x".
*
* @return This value represented as hexadecimal, starting with "0x".
*/
default String toHexString() {
return appendHexTo(new StringBuilder("0x")).toString();
}

/**
* Provides this value represented as hexadecimal, with no prefix
*
* @return This value represented as hexadecimal, with no prefix.
*/
default String toUnprefixedHexString() {
Expand All @@ -1511,7 +1530,11 @@ default String toEllipsisHexString() {
return appendable.toString();
}

/** @return This value represented as a minimal hexadecimal string (without any leading zero). */
/**
* Provides this value represented as a minimal hexadecimal string (without any leading zero)
*
* @return This value represented as a minimal hexadecimal string (without any leading zero).
*/
default String toShortHexString() {
StringBuilder hex = appendHexTo(new StringBuilder());

Expand All @@ -1523,6 +1546,9 @@ default String toShortHexString() {
}

/**
* Provides this value represented as a minimal hexadecimal string (without any leading zero, except if it's valued
* zero or empty, in which case it returns 0x0).
*
* @return This value represented as a minimal hexadecimal string (without any leading zero, except if it's valued
* zero or empty, in which case it returns 0x0).
*/
Expand All @@ -1540,6 +1566,8 @@ default String toQuantityHexString() {
}

/**
* Provides this value represented as base 64
*
* @return This value represented as base 64.
*/
default String toBase64String() {
Expand Down
12 changes: 6 additions & 6 deletions bytes/src/main/java/org/apache/tuweni/bytes/Bytes32.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ static Bytes32 wrap(byte[] bytes) {
* words, you will have {@code wrap(value, i).get(0) == value[i]}.
* @return A {@link Bytes32} that exposes the bytes of {@code value} from {@code offset} (inclusive) to
* {@code offset + 32} (exclusive).
* @throws IndexOutOfBoundsException if {@code offset &lt; 0 || (value.length &gt; 0 && offset >=
* @throws IndexOutOfBoundsException if {@code offset < 0 || (value.length > 0 && offset >=
* value.length)}.
* @throws IllegalArgumentException if {@code length &lt; 0 || offset + 32 &gt; value.length}.
* @throws IllegalArgumentException if {@code length < 0 || offset + 32 > value.length}.
*/
static Bytes32 wrap(byte[] bytes, int offset) {
checkNotNull(bytes);
Expand Down Expand Up @@ -98,9 +98,9 @@ static Bytes32 wrap(Bytes value) {
* words, you will have {@code wrap(value, i).get(0) == value.get(i)}.
* @return A {@link Bytes32} that exposes the bytes of {@code value} from {@code offset} (inclusive) to
* {@code offset + 32} (exclusive).
* @throws IndexOutOfBoundsException if {@code offset &lt; 0 || (value.size() &gt; 0 && offset >=
* @throws IndexOutOfBoundsException if {@code offset < 0 || (value.size() > 0 && offset >=
* value.size())}.
* @throws IllegalArgumentException if {@code length &lt; 0 || offset + 32 &gt; value.size()}.
* @throws IllegalArgumentException if {@code length < 0 || offset + 32 > value.size()}.
*/
static Bytes32 wrap(Bytes value, int offset) {
checkNotNull(value);
Expand All @@ -116,7 +116,7 @@ static Bytes32 wrap(Bytes value, int offset) {
*
* @param value The bytes value pad.
* @return A {@link Bytes32} that exposes the left-padded bytes of {@code value}.
* @throws IllegalArgumentException if {@code value.size() &gt; 32}.
* @throws IllegalArgumentException if {@code value.size() > 32}.
*/
static Bytes32 leftPad(Bytes value) {
checkNotNull(value);
Expand All @@ -134,7 +134,7 @@ static Bytes32 leftPad(Bytes value) {
*
* @param value The bytes value pad.
* @return A {@link Bytes32} that exposes the rightw-padded bytes of {@code value}.
* @throws IllegalArgumentException if {@code value.size() &gt; 32}.
* @throws IllegalArgumentException if {@code value.size() > 32}.
*/
static Bytes32 rightPad(Bytes value) {
checkNotNull(value);
Expand Down
12 changes: 6 additions & 6 deletions bytes/src/main/java/org/apache/tuweni/bytes/Bytes48.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ static Bytes48 wrap(byte[] bytes) {
* words, you will have {@code wrap(value, i).get(0) == value[i]}.
* @return A {@link Bytes48} that exposes the bytes of {@code value} from {@code offset} (inclusive) to
* {@code offset + 48} (exclusive).
* @throws IndexOutOfBoundsException if {@code offset &lt; 0 || (value.length &gt; 0 && offset >=
* @throws IndexOutOfBoundsException if {@code offset < 0 || (value.length > 0 && offset >=
* value.length)}.
* @throws IllegalArgumentException if {@code length &lt; 0 || offset + 48 &gt; value.length}.
* @throws IllegalArgumentException if {@code length < 0 || offset + 48 > value.length}.
*/
static Bytes48 wrap(byte[] bytes, int offset) {
checkNotNull(bytes);
Expand Down Expand Up @@ -98,9 +98,9 @@ static Bytes48 wrap(Bytes value) {
* words, you will have {@code wrap(value, i).get(0) == value.get(i)}.
* @return A {@link Bytes48} that exposes the bytes of {@code value} from {@code offset} (inclusive) to
* {@code offset + 48} (exclusive).
* @throws IndexOutOfBoundsException if {@code offset &lt; 0 || (value.size() &gt; 0 && offset >=
* @throws IndexOutOfBoundsException if {@code offset < 0 || (value.size() > 0 && offset >=
* value.size())}.
* @throws IllegalArgumentException if {@code length &lt; 0 || offset + 48 &gt; value.size()}.
* @throws IllegalArgumentException if {@code length < 0 || offset + 48 > value.size()}.
*/
static Bytes48 wrap(Bytes value, int offset) {
checkNotNull(value);
Expand All @@ -119,7 +119,7 @@ static Bytes48 wrap(Bytes value, int offset) {
*
* @param value The bytes value pad.
* @return A {@link Bytes48} that exposes the left-padded bytes of {@code value}.
* @throws IllegalArgumentException if {@code value.size() &gt; 48}.
* @throws IllegalArgumentException if {@code value.size() > 48}.
*/
static Bytes48 leftPad(Bytes value) {
checkNotNull(value);
Expand All @@ -138,7 +138,7 @@ static Bytes48 leftPad(Bytes value) {
*
* @param value The bytes value pad.
* @return A {@link Bytes48} that exposes the rightw-padded bytes of {@code value}.
* @throws IllegalArgumentException if {@code value.size() &gt; 48}.
* @throws IllegalArgumentException if {@code value.size() > 48}.
*/
static Bytes48 rightPad(Bytes value) {
checkNotNull(value);
Expand Down

0 comments on commit fa65c18

Please sign in to comment.