English 中文(简体)
FindBugs and CheckForNull on classes vs. interfaces
原标题:

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.

最佳回答

Yes you can write your own detectors, and package them in your own jar plugin file. See fb-contrib.sf.net as an example of an auxillary findbugs plugin.

The one issue is that FindBugs relies on bcel 5.2 which doesn t have annotation support yet. You still get the attributes passed to you that represent the annotations, but it s more manual coding than will be the case in 5.3 (or whatever the next version of bcel is).

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签