Skip to content

Commit

Permalink
Fix a number of issues that Error Prone detected (fixes #2054)
Browse files Browse the repository at this point in the history
  • Loading branch information
vorburger authored and remkop committed Dec 16, 2023
1 parent 4d70874 commit ca0b8b4
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
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

0 comments on commit ca0b8b4

Please sign in to comment.