Product: SonarQube Community (self-hosted)
sonar-java version: sonar-java 8.28.0.43176 on SonarQube Community Build 26.4.0.121862
Java source level: 21 (javac 21, source/target 17)
Rule
java:S2201 — Return values from functions without side effects should not be ignored
Description
java:S2201 flags ignored Stream#anyMatch results on boxed streams but misses the equivalent calls on primitive streams (IntStream, LongStream, DoubleStream). Since all anyMatch variants are side-effect-free and return a boolean, the primitive-stream cases are false negatives.
Reproducer
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;
public class PrimitiveStreamAnyMatch {
// Flagged correctly by S2201
void boxed() {
Stream<Integer> s = Stream.of(1).filter(i -> i < 5);
s.anyMatch(i -> i < 5);
}
// NOT flagged — should be (false negative)
void ints() {
IntStream s = IntStream.of(1).filter(i -> i < 5);
s.anyMatch(i -> i < 5);
}
void longs() {
LongStream s = LongStream.of(1L).filter(i -> i < 5L);
s.anyMatch(i -> i < 5L);
}
void doubles() {
DoubleStream s = DoubleStream.of(1.0).filter(i -> i < 5.0);
s.anyMatch(i -> i < 5.0);
}
}
Expected behavior
java:S2201 raises an issue on each IntStream/LongStream/DoubleStream#anyMatch call whose boolean result is discarded, identical to the Stream<T>#anyMatch case.
Actual behavior
No issue is reported for the primitive‑stream anyMatch calls; only the Stream<Integer>/Long/Double#anyMatch calls are flagged.