diff --git a/mug-errorprone/src/main/java/com/google/mu/errorprone/StringFormatArgsCheck.java b/mug-errorprone/src/main/java/com/google/mu/errorprone/StringFormatArgsCheck.java index 7d174777c..cd7d91bb6 100644 --- a/mug-errorprone/src/main/java/com/google/mu/errorprone/StringFormatArgsCheck.java +++ b/mug-errorprone/src/main/java/com/google/mu/errorprone/StringFormatArgsCheck.java @@ -306,7 +306,9 @@ private void checkDuplicatePlaceholderNames( VisitorState state) throws ErrorReport { ImmutableListMultimap allPlaceholders = - BiStream.zip(placeholderVariableNames, args).collect(toImmutableListMultimap()); + BiStream.zip(placeholderVariableNames, args) + .skipKeysIf("..."::equals) // wildcard doesn't count as duplicate name + .collect(toImmutableListMultimap()); for (Map.Entry> entry : Multimaps.asMap(allPlaceholders).entrySet()) { List conflicts = diff --git a/mug-errorprone/src/test/java/com/google/mu/errorprone/StringFormatArgsCheckTest.java b/mug-errorprone/src/test/java/com/google/mu/errorprone/StringFormatArgsCheckTest.java index 7e826ca9d..1cbde86c7 100644 --- a/mug-errorprone/src/test/java/com/google/mu/errorprone/StringFormatArgsCheckTest.java +++ b/mug-errorprone/src/test/java/com/google/mu/errorprone/StringFormatArgsCheckTest.java @@ -2207,6 +2207,22 @@ public void format_duplicatePlaceholderNameWithConflictingValues() { .doTest(); } + @Test + public void to_wildcardDoesNotCountAsDuplicateName() { + helper + .addSourceLines( + "Test.java", + "import com.google.mu.util.StringFormat;", + "class Test {", + " private static final StringFormat.Template TEMPLATE =", + " StringFormat.to(IllegalArgumentException::new, \"{...}={...}\");", + " void test() {", + " TEMPLATE.with(1, 2);", + " }", + "}") + .doTest(); + } + @Test public void format_duplicatePlaceholderNameWithConsistentValues() { helper