Affects PMD Version: 7.22.0
Rule:UselessPureMethodCall
Description:
The UselessPureMethodCall rule correctly detects useless peek() calls on java.util.stream.Stream, but completely fails to trigger on the exact same anti-pattern when used with the three primitive stream types (IntStream, LongStream, DoubleStream).
This is a clear false negative — the returned stream is discarded in all cases, yet only the reference Stream is flagged.
Code Sample demonstrating the issue:
import java.util.stream.Stream;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.DoubleStream;
public class a{
public void TP(){
Stream.of("A","B").peek(System.out::println); // TP: correctly reported
}
public void FN1(){
IntStream.of(1,2).peek(System.out::println); // FN: should report
}
public void FN2(){
LongStream.of(1,2).peek(System.out::println); // FN
}
public void FN3(){
DoubleStream.of(1.0,2.0).peek(System.out::println); // FN
}
}
Expected outcome:
PMD should report all four peek calls with the message:
"Do not call pure method peek if the result is not used."
But currently it only reports the Stream case (TP), completely missing the three primitive stream cases (FN).
Running PMD through: CLI
Affects PMD Version: 7.22.0
Rule:UselessPureMethodCall
Description:
The UselessPureMethodCall rule correctly detects useless
peek()calls onjava.util.stream.Stream, but completely fails to trigger on the exact same anti-pattern when used with the three primitive stream types (IntStream,LongStream,DoubleStream).This is a clear false negative — the returned stream is discarded in all cases, yet only the reference
Streamis flagged.Code Sample demonstrating the issue:
Expected outcome:
PMD should report all four peek calls with the message:
"Do not call pure method peek if the result is not used."
But currently it only reports the Stream case (TP), completely missing the three primitive stream cases (FN).
Running PMD through: CLI