FindBugs and CheckForNull on classes vs. interfaces

Posted by ndn on Stack Overflow See other posts from Stack Overflow or by ndn
Published on 2010-03-10T09:39:22Z Indexed on 2010/04/29 3:17 UTC
Read the original article Hit count: 213

Filed under:
|
|
|

Is there any way to let FindBugs check and warn me if a CheckForNull annotation is present on the implementation of a method in a class, but not on the declaration of the method in the interface?

import javax.annotation.CheckForNull;

interface Foo {
    public String getBar();
}

class FooImpl implements Foo {

    @CheckForNull 
    @Override
    public String getBar() {
        return null;
    }   
}

public class FindBugsDemo {
    public static void main(String[] args) {
        Foo foo = new FooImpl();
        System.out.println(foo.getBar().length());
    }
}

I just discovered a bug in my application due to a missing null check that was not spotted by FindBugs because CheckForNull was only present on FooImpl, but not on Foo, and I don't want to spot all other locations of this problem manually.

© Stack Overflow or respective owner

Related posts about findbugs

Related posts about java