diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/SameNameButDifferent.java b/core/src/main/java/com/google/errorprone/bugpatterns/SameNameButDifferent.java index fccb79c97a5..9669aded089 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/SameNameButDifferent.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/SameNameButDifferent.java @@ -185,15 +185,16 @@ private void handle(Tree tree) { .map(t -> t.getQualifiedName().toString()) .collect(joining(", ", "[", "]"))); SuggestedFix fix = fixBuilder.build(); - for (List treePaths : trimmedTable.row(simpleName).values()) { - for (TreePath treePath : treePaths) { - state.reportMatch( - buildDescription(treePath.getLeaf()).setMessage(message).addFix(fix).build()); - if (batchFindings) { - break; - } - } - } + trimmedTable.row(simpleName).values().stream() + .flatMap(List::stream) + .limit(batchFindings ? 1 : Long.MAX_VALUE) + .forEach( + treePath -> + state.reportMatch( + buildDescription(treePath.getLeaf()) + .setMessage(message) + .addFix(fix) + .build())); } } return NO_MATCH; diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/SameNameButDifferentTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/SameNameButDifferentTest.java index 184c086e6f6..66633c57068 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/SameNameButDifferentTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/SameNameButDifferentTest.java @@ -224,7 +224,6 @@ public void ungroupedOverloadsPositiveCasesCoveringOnlyFirstOverload() { " }", " class Two {", " class Clash {}", - " // BUG: Diagnostic contains:", " Clash a;", " Clash b;", " }",