score:2

Accepted answer

this may be obvious, but i think your issues are with eclipse (perhaps the findbugs plugin in particular), not findbugs itself.

you might consider running findbugs from the command line to eliminate any eclipse issues and ensure that you have findbugs running correctly in its own. knowing how to run findbugs in a standalone mode will give you a fallback when your ide is not configured properly.

i saved your source code in a file named findbugsannotationstest.java, added imports for list, arraylist, and checkfornull, compiled, and ran findbugs 1.3.9. findbugs generates several warnings about null values:

m d np: possible null pointer dereference in findbugsannotationstest.shouldgetfindbugswarning() due to return value of called method  dereferenced at findbugsannotationstest.java:[line 18]
m c uwf: unwritten field: findbugsannotationstest.canbenull  at findbugsannotationstest.java:[line 12]
m c np: read of unwritten field canbenull in findbugsannotationstest.shouldgetfindbugswarning()  at findbugsannotationstest.java:[line 16]
warnings generated: 3

these are the imports i added to the top of findbugsannotationstest.java:

import java.util.arraylist;
import java.util.list;
import edu.umd.cs.findbugs.annotations.checkfornull;

commands:

javac -d . -classpath ${findbugs_home}/lib/findbugs.jar findbugsannotationstest.java
${findbugs_home}/bin/findbugs findbugsannotationstest.class

where ${findbugs_home} is the directory in which findbugs 1.3.9 is installed. javac is assumed to be on the path.

note: i used the findbugs.jar instead of annotations.jar and jsr305.jar but i get the same results with this command:

javac -d . -classpath ${findbugs_home}/lib/annotations.jar:${findbugs_home}/lib/jsr305.jar findbugsannotationstest.java

Related Query

More Query from same tag