Skip to content

Commit 9e7a834

Browse files
cpovirkError Prone Team
authored andcommitted
Recognize that checkPositionIndex isn't a lenient-format-string method, either.
Compare c0877ea. PiperOrigin-RevId: 831582354
1 parent 961d131 commit 9e7a834

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

core/src/main/java/com/google/errorprone/bugpatterns/formatstring/LenientFormatStringUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static int getLenientFormatStringPosition(ExpressionTree tree, VisitorSta
4646
new LenientFormatMethod(
4747
staticMethod()
4848
.onClass("com.google.common.base.Preconditions")
49-
.withNameMatching(compile("^check(?!ElementIndex).*")),
49+
.withNameMatching(compile("^check(?!ElementIndex|PositionIndex).*")),
5050
1),
5151
new LenientFormatMethod(
5252
staticMethod()

core/src/test/java/com/google/errorprone/bugpatterns/formatstring/FormatStringShouldUsePlaceholdersTest.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public void preconditions(int i, Object o) {
113113
}
114114

115115
@Test
116-
public void negativeCheckArgumentIndex() {
116+
public void negativeCheckElementIndex() {
117117
refactoringHelper
118118
.addInputLines(
119119
"Test.java",
@@ -125,6 +125,24 @@ public void checkElementIndex(int i, int j) {
125125
Preconditions.checkElementIndex(i, j + 10);
126126
}
127127
}
128+
""")
129+
.expectUnchanged()
130+
.doTest();
131+
}
132+
133+
@Test
134+
public void negativeCheckPositionIndex() {
135+
refactoringHelper
136+
.addInputLines(
137+
"Test.java",
138+
"""
139+
import com.google.common.base.Preconditions;
140+
141+
public class Test {
142+
public void checkPositionIndex(int i, int j) {
143+
Preconditions.checkPositionIndex(i, j + 10);
144+
}
145+
}
128146
""")
129147
.expectUnchanged()
130148
.doTest();

0 commit comments

Comments
 (0)