Skip to content

Commit 1e33976

Browse files
committed
Fixes various issues found in static code inspection
E.g typos, weaker access, redundant "throws exception"
1 parent 201457e commit 1e33976

File tree

11 files changed

+42
-44
lines changed

11 files changed

+42
-44
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
We ❤ pull requests from everyone.
44

5-
If possible proof features and bugfixes with unit tests.
5+
If possible proof features and bug fixes with unit tests.
66
This repo validates against checkstyle (import the xml found in the root to your IDE if possible)
77

88
To run the tests (and checkstyle):
@@ -12,4 +12,4 @@ mvn test checkstyle:check
1212
```
1313

1414
Tests are automatically run against branches and pull requests
15-
via TravisCI, so you can also depend on that.
15+
via TravisCI, so you can also depend on that.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Add dependency to your `pom.xml` ([check latest release](https://github.com/patr
5454
<version>{latest-version}</version>
5555
</dependency>
5656

57-
_Note:_ There is a byte-code optimized version (powerd by [ProGuard](https://www.guardsquare.com/en/products/proguard)) which can be used with [classifier](https://maven.apache.org/pom.html#Maven_Coordinates) 'optimized'. This may have issues so use at your own risk.
57+
_Note:_ There is a byte-code optimized version (powered by [ProGuard](https://www.guardsquare.com/en/products/proguard)) which can be used with [classifier](https://maven.apache.org/pom.html#Maven_Coordinates) 'optimized'. This may have issues so use at your own risk.
5858

5959
Some simple examples:
6060

src/main/java/at/favre/lib/bytes/Bytes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ public Bytes hash(String algorithm) {
10811081
* This transformation might be done in-place (ie. without copying the internal array and overwriting its old state),
10821082
* or on a copy of the internal data, depending on the type (e.g. {@link MutableBytes}) and if the operation can be done
10831083
* in-place. Therefore the caller has to ensure that certain side-effects, which occur due to the changing of the internal
1084-
* data, do not create bugs in his/her code. Usually immutability is prefered, but when handling many or big byte arrays,
1084+
* data, do not create bugs in his/her code. Usually immutability is preferred, but when handling many or big byte arrays,
10851085
* mutability enables drastically better performance.
10861086
*
10871087
* @param transformer used to transform this instance

src/main/java/at/favre/lib/bytes/BytesTransformers.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
/**
1919
* Collection of additional {@link BytesTransformer} for more specific use cases
2020
*/
21+
@SuppressWarnings("WeakerAccess")
2122
public final class BytesTransformers {
2223

2324
private BytesTransformers() {
@@ -222,7 +223,7 @@ public boolean supportInPlaceTransformation() {
222223
}
223224

224225
/**
225-
* Converting each byte into unsinged version and comparing it (0...255) vs (-128..127)
226+
* Converting each byte into unsigned version and comparing it (0...255) vs (-128..127)
226227
*/
227228
static final class UnsignedByteComparator implements Comparator<Byte> {
228229
@Override
@@ -246,7 +247,7 @@ public static final class ChecksumTransformer implements BytesTransformer {
246247

247248
ChecksumTransformer(Checksum checksum, Mode mode, int checksumLengthByte) {
248249
if (checksumLengthByte <= 0 || checksumLengthByte > 8)
249-
throw new IllegalArgumentException("checksumlength must be between 1 and 8 bytes");
250+
throw new IllegalArgumentException("checksum length must be between 1 and 8 bytes");
250251

251252
Objects.requireNonNull(checksum, "checksum instance must not be null");
252253
this.checksum = checksum;

src/main/java/at/favre/lib/bytes/BytesValidators.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
/**
2828
* Util and easy access for {@link BytesValidators}
2929
*/
30+
@SuppressWarnings("WeakerAccess")
3031
public final class BytesValidators {
3132

3233
private BytesValidators() {

src/test/java/at/favre/lib/bytes/ABytesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
import static org.junit.Assert.*;
2929

30-
public abstract class ABytesTest {
30+
abstract class ABytesTest {
3131
byte[] example_bytes_empty;
3232

3333
byte[] example_bytes_one;
@@ -55,7 +55,7 @@ public abstract class ABytesTest {
5555
String example_hex_twentyfour;
5656

5757
@Before
58-
public void setUp() throws Exception {
58+
public void setUp() {
5959
example_bytes_empty = new byte[0];
6060
example_bytes_one = new byte[]{0x67};
6161
example_hex_one = "67";

src/test/java/at/favre/lib/bytes/BytesByteOrderTest.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
public class BytesByteOrderTest extends ABytesTest {
3232

3333
@Test
34-
public void miscInput() throws Exception {
34+
public void miscInput() {
3535
testOrder(Bytes.from(350));
3636
testOrder(Bytes.from(172863182736L));
3737
testOrder(Bytes.from(example_bytes_one));
@@ -52,82 +52,82 @@ private void testOrder(Bytes bytes) {
5252
}
5353

5454
@Test
55-
public void encodeBinary() throws Exception {
55+
public void encodeBinary() {
5656
Bytes b = Bytes.from(example_bytes_four);
5757
assertNotEquals(b.byteOrder(ByteOrder.BIG_ENDIAN).encodeBinary(), b.byteOrder(ByteOrder.LITTLE_ENDIAN).encodeBinary());
5858
assertEquals(b.byteOrder(ByteOrder.BIG_ENDIAN).encodeBinary(), b.byteOrder(ByteOrder.LITTLE_ENDIAN).reverse().encodeBinary());
5959
}
6060

6161
@Test
62-
public void encodeOct() throws Exception {
62+
public void encodeOct() {
6363
Bytes b = Bytes.from(example_bytes_four);
6464
assertNotEquals(b.byteOrder(ByteOrder.BIG_ENDIAN).encodeOctal(), b.byteOrder(ByteOrder.LITTLE_ENDIAN).encodeOctal());
6565
assertEquals(b.byteOrder(ByteOrder.BIG_ENDIAN).encodeOctal(), b.byteOrder(ByteOrder.LITTLE_ENDIAN).reverse().encodeOctal());
6666
}
6767

6868
@Test
69-
public void encodeDec() throws Exception {
69+
public void encodeDec() {
7070
Bytes b = Bytes.from(example_bytes_four);
7171
assertNotEquals(b.byteOrder(ByteOrder.BIG_ENDIAN).encodeDec(), b.byteOrder(ByteOrder.LITTLE_ENDIAN).encodeDec());
7272
assertEquals(b.byteOrder(ByteOrder.BIG_ENDIAN).encodeDec(), b.byteOrder(ByteOrder.LITTLE_ENDIAN).reverse().encodeDec());
7373
}
7474

7575
@Test
76-
public void encodeHex() throws Exception {
76+
public void encodeHex() {
7777
Bytes b = Bytes.from(example_bytes_two);
7878
assertNotEquals(b.byteOrder(ByteOrder.BIG_ENDIAN).encodeHex(), b.byteOrder(ByteOrder.LITTLE_ENDIAN).encodeHex());
7979
assertEquals(b.byteOrder(ByteOrder.BIG_ENDIAN).encodeHex(), b.byteOrder(ByteOrder.LITTLE_ENDIAN).reverse().encodeHex());
8080
}
8181

8282
@Test
83-
public void encodeBase36() throws Exception {
83+
public void encodeBase36() {
8484
Bytes b = Bytes.from(example_bytes_four);
8585
assertNotEquals(b.byteOrder(ByteOrder.BIG_ENDIAN).encodeBase36(), b.byteOrder(ByteOrder.LITTLE_ENDIAN).encodeBase36());
8686
assertEquals(b.byteOrder(ByteOrder.BIG_ENDIAN).encodeBase36(), b.byteOrder(ByteOrder.LITTLE_ENDIAN).reverse().encodeBase36());
8787
}
8888

8989
@Test
90-
public void encodeBase64() throws Exception {
90+
public void encodeBase64() {
9191
Bytes b = Bytes.from(example_bytes_four);
9292
assertNotEquals(b.byteOrder(ByteOrder.BIG_ENDIAN).encodeBase64(), b.byteOrder(ByteOrder.LITTLE_ENDIAN).encodeBase64());
9393
assertEquals(b.byteOrder(ByteOrder.BIG_ENDIAN).encodeBase64(), b.byteOrder(ByteOrder.LITTLE_ENDIAN).reverse().encodeBase64());
9494
}
9595

9696
@Test
97-
public void toByte() throws Exception {
97+
public void toByte() {
9898
Bytes b = Bytes.from(example_bytes_one);
9999
assertEquals(b.byteOrder(ByteOrder.BIG_ENDIAN).toByte(), b.byteOrder(ByteOrder.LITTLE_ENDIAN).toByte());
100100
}
101101

102102
@Test
103-
public void toChar() throws Exception {
103+
public void toChar() {
104104
Bytes b = Bytes.from(example_bytes_two);
105105
assertNotEquals(b.byteOrder(ByteOrder.BIG_ENDIAN).toChar(), b.byteOrder(ByteOrder.LITTLE_ENDIAN).toChar());
106106
}
107107

108108
@Test
109-
public void toShort() throws Exception {
109+
public void toShort() {
110110
Bytes b = Bytes.from(example_bytes_two);
111111
assertNotEquals(b.byteOrder(ByteOrder.BIG_ENDIAN).toShort(), b.byteOrder(ByteOrder.LITTLE_ENDIAN).toShort());
112112
}
113113

114114
@Test
115-
public void toInt() throws Exception {
115+
public void toInt() {
116116
Bytes b = Bytes.from(example_bytes_four);
117117
assertNotEquals(b.byteOrder(ByteOrder.BIG_ENDIAN).toInt(), b.byteOrder(ByteOrder.LITTLE_ENDIAN).toInt());
118118
}
119119

120120
@Test
121-
public void toLong() throws Exception {
121+
public void toLong() {
122122
Bytes b = Bytes.from(example_bytes_eight);
123123
assertNotEquals(b.byteOrder(ByteOrder.BIG_ENDIAN).toLong(), b.byteOrder(ByteOrder.LITTLE_ENDIAN).toLong());
124124
}
125125

126126
@Test
127-
public void bigInteger() throws Exception {
127+
public void bigInteger() {
128128
Bytes b = Bytes.from(example_bytes_four);
129129
assertNotEquals(b.byteOrder(ByteOrder.BIG_ENDIAN).toBigInteger(), b.byteOrder(ByteOrder.LITTLE_ENDIAN).toBigInteger());
130130
assertEquals(b.byteOrder(ByteOrder.BIG_ENDIAN).toBigInteger(), b.byteOrder(ByteOrder.LITTLE_ENDIAN).reverse().toBigInteger());
131131
}
132132

133-
}
133+
}

src/test/java/at/favre/lib/bytes/BytesConstructorTests.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@
2626
import org.junit.Test;
2727
import org.junit.rules.TemporaryFolder;
2828

29-
import java.io.ByteArrayInputStream;
30-
import java.io.DataInput;
31-
import java.io.DataInputStream;
32-
import java.io.File;
33-
import java.io.FileOutputStream;
29+
import java.io.*;
3430
import java.math.BigInteger;
3531
import java.nio.ByteBuffer;
3632
import java.nio.ByteOrder;
@@ -48,7 +44,7 @@
4844

4945
public class BytesConstructorTests extends ABytesTest {
5046
@Rule
51-
public TemporaryFolder testFolder = new TemporaryFolder();
47+
public final TemporaryFolder testFolder = new TemporaryFolder();
5248

5349
@Test
5450
public void wrapTest() {

src/test/java/at/favre/lib/bytes/BytesMiscTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,14 @@ public void testCompareTo() {
121121

122122
assertTrue(-1 >= Bytes.from(b1).compareTo(Bytes.from(b2)));
123123
assertTrue(1 <= Bytes.from(b2).compareTo(Bytes.from(b1)));
124-
assertTrue(0 == Bytes.from(b1).compareTo(Bytes.from(b1)));
124+
assertEquals(0, Bytes.from(b1).compareTo(Bytes.from(b1)));
125125

126126
byte[] bOne = new byte[]{0x01};
127127
byte[] bTwo = new byte[]{0x02};
128128

129129
assertTrue(-1 >= Bytes.from(bOne).compareTo(Bytes.from(bTwo)));
130130
assertTrue(1 <= Bytes.from(bTwo).compareTo(Bytes.from(bOne)));
131-
assertTrue(0 == Bytes.from(bOne).compareTo(Bytes.from(bOne)));
131+
assertEquals(0, Bytes.from(bOne).compareTo(Bytes.from(bOne)));
132132
}
133133

134134
@Test
@@ -507,7 +507,7 @@ public void readOnly() {
507507
try {
508508
Bytes.from(example_bytes_twentyfour).readOnly().array();
509509
fail();
510-
} catch (ReadOnlyBufferException e) {
510+
} catch (ReadOnlyBufferException ignored) {
511511
}
512512

513513
Bytes b = Bytes.from(example_bytes_twentyfour).readOnly();

src/test/java/at/favre/lib/bytes/BytesValidatorTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
public class BytesValidatorTest extends ABytesTest {
3333

3434
@Test
35-
public void testOnlyOfValidator() throws Exception {
35+
public void testOnlyOfValidator() {
3636
assertFalse(Bytes.allocate(0).validateNotOnlyZeros());
3737
assertFalse(Bytes.allocate(2).validateNotOnlyZeros());
3838
assertTrue(Bytes.wrap(example_bytes_seven).validateNotOnlyZeros());
@@ -50,7 +50,7 @@ public void testOnlyOfValidator() throws Exception {
5050
}
5151

5252
@Test
53-
public void testLengthValidators() throws Exception {
53+
public void testLengthValidators() {
5454
assertFalse(Bytes.allocate(0).validate(atLeast(1)));
5555
assertTrue(Bytes.allocate(1).validate(atLeast(1)));
5656
assertTrue(Bytes.allocate(2).validate(atLeast(1)));
@@ -65,7 +65,7 @@ public void testLengthValidators() throws Exception {
6565
}
6666

6767
@Test
68-
public void testOrValidation() throws Exception {
68+
public void testOrValidation() {
6969
assertTrue(Bytes.allocate(0).validate(or(exactLength(1), exactLength(0))));
7070
assertTrue(Bytes.allocate(2).validate(or(atLeast(3), onlyOf((byte) 0))));
7171
assertTrue(Bytes.allocate(3).validate(or(onlyOf((byte) 1), onlyOf((byte) 0))));
@@ -74,34 +74,34 @@ public void testOrValidation() throws Exception {
7474
}
7575

7676
@Test
77-
public void testAndValidation() throws Exception {
77+
public void testAndValidation() {
7878
assertFalse(Bytes.allocate(5).validate(and(atLeast(3), notOnlyOf((byte) 0))));
7979
assertFalse(Bytes.wrap(new byte[]{1, 0}).validate(and(atLeast(3), notOnlyOf((byte) 0))));
8080
assertTrue(Bytes.wrap(new byte[]{1, 0, 0}).validate(and(atLeast(3), notOnlyOf((byte) 0))));
8181
assertFalse(Bytes.allocate(21).validate(and(atLeast(3), atMost(20))));
8282
}
8383

8484
@Test
85-
public void testNotValidation() throws Exception {
85+
public void testNotValidation() {
8686
assertEquals(Bytes.allocate(2).validate(not(onlyOf((byte) 0))), Bytes.allocate(2).validate(notOnlyOf((byte) 0)));
8787
assertTrue(Bytes.allocate(2).validate(not(atLeast(16))));
8888
assertFalse(Bytes.allocate(2).validate(not(atMost(16))));
8989
}
9090

9191
@Test(expected = IllegalArgumentException.class)
92-
public void testLogicalNoElements() throws Exception {
92+
public void testLogicalNoElements() {
9393
Bytes.allocate(2).validate(new BytesValidator.Logical(Collections.<BytesValidator>emptyList(), BytesValidator.Logical.Operator.AND));
9494
}
9595

9696
@Test(expected = IllegalArgumentException.class)
97-
public void testLogicalTooManyElements() throws Exception {
97+
public void testLogicalTooManyElements() {
9898
Bytes.allocate(2).validate(new BytesValidator.Logical(
9999
Arrays.<BytesValidator>asList(new BytesValidator.Length(2, BytesValidator.Length.Mode.GREATER_OR_EQ_THAN), new BytesValidator.Length(2, BytesValidator.Length.Mode.EXACT))
100100
, BytesValidator.Logical.Operator.NOT));
101101
}
102102

103103
@Test
104-
public void testNestedValidation() throws Exception {
104+
public void testNestedValidation() {
105105
assertTrue(Bytes.allocate(16).validate(
106106
or(and(atLeast(8), not(onlyOf(((byte) 0)))),
107107
or(exactLength(16), exactLength(12)))));
@@ -113,7 +113,7 @@ public void testNestedValidation() throws Exception {
113113
}
114114

115115
@Test
116-
public void testStartWithValidate() throws Exception {
116+
public void testStartWithValidate() {
117117
assertTrue(Bytes.wrap(new byte[]{0, 3, 0}).validate(startsWith((byte) 0, (byte) 3)));
118118
assertFalse(Bytes.wrap(new byte[]{0, 2, 0}).validate(startsWith((byte) 0, (byte) 3)));
119119
assertTrue(Bytes.wrap(new byte[]{0, 2, 0}).validate(startsWith((byte) 0)));
@@ -123,12 +123,12 @@ public void testStartWithValidate() throws Exception {
123123
}
124124

125125
@Test
126-
public void testEndsWithValidate() throws Exception {
126+
public void testEndsWithValidate() {
127127
assertTrue(Bytes.wrap(new byte[]{1, 2, 3}).validate(endsWith((byte) 2, (byte) 3)));
128128
assertFalse(Bytes.wrap(new byte[]{0, 2, 0}).validate(endsWith((byte) 3, (byte) 0)));
129129
assertTrue(Bytes.wrap(new byte[]{0, 2, 0}).validate(endsWith((byte) 0)));
130130
assertFalse(Bytes.wrap(new byte[]{0, 2, 0}).validate(endsWith((byte) 2)));
131131
assertTrue(Bytes.allocate(16).validate(endsWith((byte) 0)));
132132
assertFalse(Bytes.allocate(16).validate(endsWith(Bytes.allocate(17).array())));
133133
}
134-
}
134+
}

0 commit comments

Comments
 (0)