The RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE check is generating a warning only when using !=, but it should also warn when using ==.
public class TestNonnull
{
@Nonnull
private final List<Integer> foo = Collections.emptyList();
public void test() {
if (foo != null) { // warning, good
throw new IllegalStateException();
}
if (foo == null) { // no warning, bad
throw new IllegalStateException();
}
}
}
OK, findbugs is working an intended here. When it sees an infeasible null check that always leads to an explicit exception being thrown, it assume the check is a defensive check and doesn't warn about it.
If you put each check in a separate method, and change the throw to a println, it complains about both.
If you leave both checks in the same method, but change the throw to printlns, we only report one of them. This is due to a separate issue when trying to collapse multiple reports of the same issue, but with different priorities. I've fixed that problem.