Example where Sonar incorrectly suggests replacing with IntSupplier
:
Supplier<Integer> supplier = condition
? counter::incrementAndGet
: () -> null;
Related thread: java:S4276 reports false positive on Supplier<Boolean> which can supply null values
Related ticket: Jira
I understand that it may not be easy to determine whether return value can be null or not (when a chain of method calls are involved), but in this case the null
value is a literal in the same file. Maybe Sonar could handle such cases easily?