A stream is collected with a collector that only repeats a stream operation, such as counting() for count()

tx0/java:top-level-collectorstrictwarningstyle/conventionsdepth faststyle

What it finds

collect(Collectors.counting()) is count(), collect(Collectors.minBy(c)) is min(c), collect(Collectors.reducing(...)) is reduce(...), and collect(Collectors.mapping(f, c)) is map(f).collect(c). The collectors exist to be nested inside others, such as groupingBy; at the top level the stream operation is shorter.

Reported is collect given one of counting, minBy, maxBy, reducing, mapping, filtering, flatMapping, summingInt, summingLong, summingDouble, averagingInt, averagingLong or averagingDouble of Collectors.

From the rule's source, redundant_collector.rs.

Example from the rule's tests
import java.util.List;import java.util.stream.Collectors; class Collect {  Object run(List<String> items) {    long a = items.stream().collect(Collectors.counting());tx0 reports: counting at the top level    Object b = items.stream().collect(Collectors.groupingBy(String::length, Collectors.counting()));    return a + "" + b;  }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/java:top-level-collector" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/java:top-level-collector] reason="..."

tx0 explain tx0/java:top-level-collector shows the same in the terminal. Found a false positive? Report it.