Skip to content

Commit ed4b61d

Browse files
cushonError Prone Team
authored and
Error Prone Team
committed
Fix an ArrayToString false positive for the varargs overload of Joiner.join(Object, Object, Object...)
#4233 (review) PiperOrigin-RevId: 619537499
1 parent 9b2c2a9 commit ed4b61d

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

core/src/main/java/com/google/errorprone/bugpatterns/AbstractToString.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,9 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState
201201
argTree,
202202
ToStringKind.IMPLICIT,
203203
state);
204+
} else {
205+
handleStringifiedTree(argTree, ToStringKind.IMPLICIT, state);
204206
}
205-
handleStringifiedTree(argTree, ToStringKind.IMPLICIT, state);
206207
}
207208
}
208209
}

core/src/test/java/com/google/errorprone/bugpatterns/ArrayToStringTest.java

+29
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,33 @@ public void arrayPassedToJoiner() {
199199
"}")
200200
.doTest();
201201
}
202+
203+
@Test
204+
public void arrayPassedToJoiner_firstSecondRest_negative() {
205+
compilationHelper
206+
.addSourceLines(
207+
"Test.java",
208+
"import com.google.common.base.Joiner;",
209+
"class Test {",
210+
" String test(Joiner j, Object first, Object second, Object[] rest) {",
211+
" return j.join(first, second, rest);",
212+
" }",
213+
"}")
214+
.doTest();
215+
}
216+
217+
@Test
218+
public void arrayPassedToJoiner_firstSecondRest_positive() {
219+
compilationHelper
220+
.addSourceLines(
221+
"Test.java",
222+
"import com.google.common.base.Joiner;",
223+
"class Test {",
224+
" String test(Joiner j, Object first, Object second, Object third, Object[] rest) {",
225+
" // BUG: Diagnostic contains:",
226+
" return j.join(first, second, third, rest);",
227+
" }",
228+
"}")
229+
.doTest();
230+
}
202231
}

0 commit comments

Comments
 (0)