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