diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/AbstractToString.java b/core/src/main/java/com/google/errorprone/bugpatterns/AbstractToString.java index 94feba2dc590..7b20727d242c 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/AbstractToString.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/AbstractToString.java @@ -201,8 +201,9 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState argTree, ToStringKind.IMPLICIT, state); + } else { + handleStringifiedTree(argTree, ToStringKind.IMPLICIT, state); } - handleStringifiedTree(argTree, ToStringKind.IMPLICIT, state); } } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ArrayToStringTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ArrayToStringTest.java index 1014d8798c23..73b13cbdc110 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ArrayToStringTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ArrayToStringTest.java @@ -199,4 +199,33 @@ public void arrayPassedToJoiner() { "}") .doTest(); } + + @Test + public void arrayPassedToJoiner_firstSecondRest_negative() { + compilationHelper + .addSourceLines( + "Test.java", + "import com.google.common.base.Joiner;", + "class Test {", + " String test(Joiner j, Object first, Object second, Object[] rest) {", + " return j.join(first, second, rest);", + " }", + "}") + .doTest(); + } + + @Test + public void arrayPassedToJoiner_firstSecondRest_positive() { + compilationHelper + .addSourceLines( + "Test.java", + "import com.google.common.base.Joiner;", + "class Test {", + " String test(Joiner j, Object first, Object second, Object third, Object[] rest) {", + " // BUG: Diagnostic contains:", + " return j.join(first, second, third, rest);", + " }", + "}") + .doTest(); + } }