Skip to content

Commit c0877ea

Browse files
cushonError Prone Team
authored andcommitted
Preconditions.checkElementIndex isn't a lenient format string method
PiperOrigin-RevId: 831305566
1 parent 9212a2c commit c0877ea

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
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.*")),
49+
.withNameMatching(compile("^check(?!ElementIndex).*")),
5050
1),
5151
new LenientFormatMethod(
5252
staticMethod()

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,22 @@ public void preconditions(int i, Object o) {
111111
""")
112112
.doTest();
113113
}
114+
115+
@Test
116+
public void negativeCheckArgumentIndex() {
117+
refactoringHelper
118+
.addInputLines(
119+
"Test.java",
120+
"""
121+
import com.google.common.base.Preconditions;
122+
123+
public class Test {
124+
public void checkElementIndex(int i, int j) {
125+
Preconditions.checkElementIndex(i, j + 10);
126+
}
127+
}
128+
""")
129+
.expectUnchanged()
130+
.doTest();
131+
}
114132
}

0 commit comments

Comments
 (0)