Skip to content

Commit 494e2c6

Browse files
klueverError Prone Team
authored andcommitted
Don't perform the inlining if parameter names are stripped.
#inlineme PiperOrigin-RevId: 672578943
1 parent dab4089 commit 494e2c6

File tree

1 file changed

+9
-2
lines changed
  • core/src/main/java/com/google/errorprone/bugpatterns/inlineme

1 file changed

+9
-2
lines changed

core/src/main/java/com/google/errorprone/bugpatterns/inlineme/Inliner.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,18 @@ && stringContainsComments(state.getSourceForNode(tree), state.context)) {
236236
}
237237

238238
for (int i = 0; i < varNames.size(); i++) {
239+
String varName = varNames.get(i);
240+
241+
// If the parameter names are missing (b/365094947), don't perform the inlining.
242+
if (varName.matches("arg[0-9]+")) {
243+
return Description.NO_MATCH;
244+
}
245+
239246
// The replacement logic below assumes the existence of another token after the parameter
240247
// in the replacement string (ex: a trailing parens, comma, dot, etc.). However, in the case
241248
// where the replacement is _just_ one parameter, there isn't a trailing token. We just make
242249
// the direct replacement here.
243-
if (replacement.equals(varNames.get(i))) {
250+
if (replacement.equals(varName)) {
244251
replacement = callingVars.get(i);
245252
break;
246253
}
@@ -252,7 +259,7 @@ && stringContainsComments(state.getSourceForNode(tree), state.context)) {
252259
String capturePrefixForVarargs = terminalVarargsReplacement ? "(?:,\\s*)?" : "\\b";
253260
// We want to avoid replacing a method invocation with the same name as the method.
254261
var extractArgAndNextToken =
255-
Pattern.compile(capturePrefixForVarargs + Pattern.quote(varNames.get(i)) + "\\b([^(])");
262+
Pattern.compile(capturePrefixForVarargs + Pattern.quote(varName) + "\\b([^(])");
256263
String replacementResult =
257264
Matcher.quoteReplacement(terminalVarargsReplacement ? "" : callingVars.get(i)) + "$1";
258265
Matcher matcher = extractArgAndNextToken.matcher(replacement);

0 commit comments

Comments
 (0)