Menu

#1248 Eclipse plugin inconsistent redundant null check

3.0.0
closed-fixed
5
2014-08-25
2014-01-27
No

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();
        }
    }
}

Discussion

  • William Pugh

    William Pugh - 2014-01-30
    • status: open --> open-accepted
    • assigned_to: William Pugh
     
  • William Pugh

    William Pugh - 2014-01-31
    • labels: --> false negative
    • status: open-accepted --> closed-fixed
     
  • William Pugh

    William Pugh - 2014-01-31

    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.

     

Log in to post a comment.