void func() {
printEvens(someCall().stream().filter(n -> n % 2 == 0).toList());
}
void printEvens(List<Integer> nums) {
nums.stream().filter(n -> n % 2 == 0).forEach(n -> System.out.println(n));
}
The first filter is redundant in this example. Duplicate code checkers are checking for exactly matching lines.I am unaware of any linter or static analyzer that would flag this.
What's more, unit tests to test the code for printEvens (there exists one) pass because they're working properly... and the unit test that calls the calling function passes because it is working properly too.
Alternatively, write the failing test for this code.