Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Error Prone #2176

Merged
merged 6 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ buildscript {
classpath "org.beryx:badass-jar:2.0.0"
classpath 'biz.aQute.bnd:biz.aQute.bnd.gradle:7.0.0'
classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.30.0"
classpath "net.ltgt.gradle:gradle-errorprone-plugin:3.1.0"
}
}

Expand Down Expand Up @@ -60,7 +61,20 @@ pluginManager.withPlugin('biz.aQute.bnd.builder') { // if plugin applied, execut
allprojects {
apply plugin: 'java'
apply plugin: 'java-library' // to avoid https://github.com/gradle/gradle/issues/1118
apply plugin: "org.beryx.jar" // for compiling module-info on Java 8
apply plugin: 'org.beryx.jar' // for compiling module-info on Java 8

// https://errorprone.info/docs/installation requires Java 11+
if (JavaVersion.current().isJava11Compatible()) {
apply plugin: "net.ltgt.errorprone"

dependencies {
errorprone("com.google.errorprone:error_prone_core:2.23.0")
}

tasks.withType(JavaCompile).configureEach {
options.errorprone.disableAllWarnings = true
}
}

if (!JavaVersion.current().isJava9Compatible()) {
sourceCompatibility = 1.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public boolean equals(Object obj) {
&& Objects.equals(other.file, this.file)
&& Objects.equals(other.rotate, this.rotate);
}

public int hashCode() {
return Objects.hash(count, file, rotate);
}
}

public static void main(String[] args) {
Expand Down
1 change: 1 addition & 0 deletions src/test/java/picocli/ArgGroupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import static org.junit.Assert.*;
import static picocli.ArgGroupTest.CommandMethodsWithGroupsAndMixins.InvokedSub.withMixin;

@SuppressWarnings("EqualsHashCode") // https://errorprone.info/bugpattern/EqualsHashCode
public class ArgGroupTest {
@Rule
public final ProvideSystemProperty ansiOFF = new ProvideSystemProperty("picocli.ansi", "false");
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/picocli/CompletionCandidatesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class App {
assertNull(candidates);
}

@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "ReturnValueIgnored"}) // iterable.iterator() https://errorprone.info/bugpattern/ReturnValueIgnored
@Test(expected = UnsupportedOperationException.class)
public void testNoCompletionCandidatesThrowsUnsupportedOperation() throws Exception {
Class<Iterable<String>> c = (Class<Iterable<String>>) Class.forName("picocli.CommandLine$NoCompletionCandidates");
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/picocli/ExecuteLegacyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@ public void run() {
new CommandLine(new App()).parseWithHandlers(new RunFirst().andExit(23),
defaultExceptionHandler().andExit(25));
assertEquals(format("" +
"blah%n",
"<main command>"), systemErrRule.getLog());
"blah%n"
), systemErrRule.getLog());
}

@SuppressWarnings("deprecation")
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/picocli/HelpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2172,7 +2172,7 @@ public void testTextTable() {
" -v, --verbose show what you're doing while you are doing it%n" +
" -p the quick brown fox jumped over the lazy dog. The%n" +
" quick brown fox jumped over the lazy dog.%n"
,""), table.toString(new StringBuilder()).toString());
), table.toString(new StringBuilder()).toString());
}

@SuppressWarnings("deprecation")
Expand All @@ -2198,7 +2198,7 @@ public void testTextTableAddsNewRowWhenAnyColumnTooLong() {
"* -c, --create, --create2, --create3, --create4, --create5, --create6,%n" +
" --create7, --create8%n" +
" description%n"
,""), table.toString(new StringBuilder()).toString());
), table.toString(new StringBuilder()).toString());

table = TextTable.forDefaultColumns(Help.Ansi.OFF, UsageMessageSpec.DEFAULT_USAGE_WIDTH);
table.addRowValues("", "-c", ",",
Expand All @@ -2208,7 +2208,7 @@ public void testTextTableAddsNewRowWhenAnyColumnTooLong() {
" -c, --create, --create2, --create3, --create4, --create5, --create6,%n" +
" --createAA7, --create8%n" +
" description%n"
,""), table.toString(new StringBuilder()).toString());
), table.toString(new StringBuilder()).toString());
}

@Test
Expand Down Expand Up @@ -2249,7 +2249,7 @@ class Cat {
" -v, --show-nonprinting use ^ and M- notation, except for LDF and TAB%n" +
" --help display this help and exit%n" +
" --version output version information and exit%n" +
"Copyright(c) 2017%n", "");
"Copyright(c) 2017%n");
assertEquals(expected, baos.toString());
}

Expand Down Expand Up @@ -2323,7 +2323,7 @@ public void testNetstatUsageFormat() {
" between each display. Press CTRL+C to stop redisplaying%n" +
" statistics. If omitted, netstat will print the current%n" +
" configuration information once.%n"
, "");
);
assertEquals(expected, CustomLayoutDemo.createNetstatUsageFormat(Help.Ansi.OFF));
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/picocli/TypeConversionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public void testTypeConversionSucceedsForValidInput() throws Exception {
"-Pattern", "a*b", //
"-UUID", "c7d51423-bf9d-45dd-a30d-5b16fafe42e2", //
"-Currency", "EUR",
"-tz", "Japan/Tokyo",
"-tz", "Asia/Tokyo",
"-byteOrder", "LITTLE_ENDIAN",
"-Class", "java.lang.String",
"-NetworkInterface", "127.0.0.0",
Expand Down Expand Up @@ -233,7 +233,7 @@ public void testTypeConversionSucceedsForValidInput() throws Exception {
assertEquals("Pattern", Pattern.compile("a*b").pattern(), bean.aPatternField.pattern());
assertEquals("UUID", UUID.fromString("c7d51423-bf9d-45dd-a30d-5b16fafe42e2"), bean.anUUIDField);
assertEquals("Currency", Currency.getInstance("EUR"), bean.aCurrencyField);
assertEquals("TimeZone", TimeZone.getTimeZone("Japan/Tokyo"), bean.aTimeZone);
assertEquals("TimeZone", TimeZone.getTimeZone("Asia/Tokyo"), bean.aTimeZone);
assertEquals("ByteOrder", ByteOrder.LITTLE_ENDIAN, bean.aByteOrder);
assertEquals("Class", String.class, bean.aClass);
assertEquals("NetworkInterface", NetworkInterface.getByInetAddress(InetAddress.getByName("127.0.0.0")), bean.aNetInterface);
Expand Down
Loading