Skip to content

Commit 6f95109

Browse files
authored
Build: Add Error Prone plugin (#155)
* Add Error-Prone annotation processor * Enable ErrorProne * Suppress warnings about StreamToString * Fix ReturnValueIgnored * Suppress warnings about EqualsHashCode * Add org.immutables:value as annotation processor * Fix ReturnValueIgnored * Add JMH generator as annotation processor * Suppress warnings about ReturnValueIgnored * Fix ReturnValueIgnored * Suppress warnings about FormatString and ArrayToString * Fix more warnings * Fix CollectionIncompatibleType * Fix FormatString
1 parent c1ec9c9 commit 6f95109

File tree

17 files changed

+70
-22
lines changed

17 files changed

+70
-22
lines changed

concurrency/src/main/java/io/mincong/concurrency/completablefuture/stackoverflow/So61957439.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
* 08:20:10.165436 - [Result{name='C3'}, Result{name='C1'}, Result{name='C2'}]
3333
* </pre>
3434
*/
35+
@SuppressWarnings("StreamToString")
3536
public class So61957439 {
3637

3738
public static void main(String[] args) throws Exception {

date/src/test/java/io/mincongh/date/so42364818/DateTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ void testDate() throws Exception {
2020
assertEquals(45, d.getMinute());
2121
assertEquals(30, d.getSecond());
2222

23-
d.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
2423
assertEquals("2009-06-15T13:45:30", d.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
2524
}
2625
}

hashcode/src/main/java/io/mincongh/hashcode/bad/AthleteOnlyOverrideEquals.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*
77
* @author Mincong Huang
88
*/
9+
@SuppressWarnings("EqualsHashCode") // hashCode() unimplemented for demo purpose
910
public class AthleteOnlyOverrideEquals {
1011

1112
private String email;

hashcode/src/main/java/io/mincongh/hashcode/bad/PhoneNumberNoHash.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.mincongh.hashcode.bad;
22

33
/** @author Mincong Huang */
4+
@SuppressWarnings("EqualsHashCode") // hashCode() unimplemented for demo purpose
45
public class PhoneNumberNoHash {
56

67
private final short areaCode;

immutables/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,10 @@
1414
<artifactId>java-examples-immutables</artifactId>
1515
<name>Java Examples - Immutables</name>
1616

17-
<properties>
18-
<immutables.version>2.8.8</immutables.version>
19-
</properties>
20-
2117
<dependencies>
2218
<dependency>
2319
<groupId>org.immutables</groupId>
2420
<artifactId>value</artifactId>
25-
<version>${immutables.version}</version>
2621
<scope>provided</scope>
2722
</dependency>
2823
<!--

java8/src/test/java/io/mincongh/java8/so2607289/ConvertArrayToListTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import static org.junit.jupiter.api.Assertions.fail;
55

66
import java.util.*;
7-
import java.util.function.Predicate;
7+
import java.util.function.Consumer;
88
import java.util.stream.Collectors;
99
import java.util.stream.Stream;
1010
import org.junit.jupiter.api.Test;
@@ -71,13 +71,13 @@ private void assertListValues(List<Integer> list) {
7171
assertEquals(3, list.get(2).intValue());
7272
}
7373

74-
private <T> void assertOperationSupported(List<T> list, Predicate<List<T>> predicate) {
75-
predicate.test(list);
74+
private <T> void assertOperationSupported(List<T> list, Consumer<List<T>> action) {
75+
action.accept(list);
7676
}
7777

78-
private <T> void assertOperationUnsupported(List<T> list, Predicate<List<T>> predicate) {
78+
private <T> void assertOperationUnsupported(List<T> list, Consumer<List<T>> action) {
7979
try {
80-
predicate.test(list);
80+
action.accept(list);
8181
fail();
8282
} catch (UnsupportedOperationException e) {
8383
// Ok

jmh/pom.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
<properties>
1818
<commons.codec.version>1.15</commons.codec.version>
19-
<jmh.version>1.26</jmh.version>
2019
</properties>
2120

2221
<dependencies>
@@ -32,12 +31,6 @@
3231
<version>${jmh.version}</version>
3332
<scope>test</scope>
3433
</dependency>
35-
<dependency>
36-
<groupId>org.openjdk.jmh</groupId>
37-
<artifactId>jmh-generator-annprocess</artifactId>
38-
<version>${jmh.version}</version>
39-
<scope>test</scope>
40-
</dependency>
4134
<dependency>
4235
<groupId>org.junit.jupiter</groupId>
4336
<artifactId>junit-jupiter-api</artifactId>

oca/src/test/java/io/mincong/ocajp/chapter3/ReviewQuestionTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public void testLegalArrayDeclaration() {
5656

5757
/** Question 31. */
5858
@Test
59+
@SuppressWarnings("ReturnValueIgnored")
5960
public void testLocalDateImmutability() {
6061
LocalDate date = LocalDate.of(2018, Month.APRIL, 30);
6162
date.plusDays(2);

ocp/src/test/java/io/mincong/ocpjp/autoboxing/WrapperClassTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public void comparingObjects() throws Exception {
6262
* Cannot use a `Float` object to retrieve the value that was
6363
* added to a `HashMap` using a `Double` instance.
6464
*/
65+
@SuppressWarnings("CollectionIncompatibleType")
6566
String value2 = map.get(new Float(2.0));
6667
assertThat(value2).isNull();
6768
}

ocp/src/test/java/io/mincong/ocpjp/collection/HashSetTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ public int hashCode() {
146146
}
147147

148148
/** Only {@link #equals(Object)} is overridden. */
149+
@SuppressWarnings("EqualsHashCode")
149150
private static class Person_E extends Person {
150151

151152
Person_E(String name) {

0 commit comments

Comments
 (0)