Findbugs using jsr305 annotations in eclipse does not find errors

I experimented with jsr 305 annotations for use with Findbugs, in particular the @CheckForNull annotation, which would avoid the error I just found to make it accessible to clients. I added jsr305.jar and annotations.jar to my build path, but no errors were found in findbugs. I am using Eclipse with the Eclipse Findbugs plugin. Below is an example of code that shows the same error, but doesn’t detect an error when findbugs starts above it. I tried this at Eclipse Galileo and Ganymede.

public class FindBugsAnnotationsTest {

    ArrayList<String> canBeNull;

    @CheckForNull
    public List<String> getCanBeNull() {
        return canBeNull;
    }

    public void shouldGetFindbugsWarning() {
    canBeNull.add("a string");

        getCanBeNull().add("a string");
    }
}
+3
source share
1 answer

, , Eclipse (, FindBugs), FindBugs.

, FindBugs , Eclipse , FindBugs . , FindBugs , , IDE .

FindBugsAnnotationsTest.java, List, ArrayList CheckForNull, FindBugs 1.3.9. FindBugs :

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

, FindBugsAnnotationsTest.java:

import java.util.ArrayList;
import java.util.List;
import edu.umd.cs.findbugs.annotations.CheckForNull;

javac -d . -classpath ${FINDBUGS_HOME}/lib/findbugs.jar FindBugsAnnotationsTest.java
${FINDBUGS_HOME}/bin/findbugs FindBugsAnnotationsTest.class

${FINDBUGS_HOME} - , Findbugs 1.3.9. javac , .

. findbugs.jar annotations.jar jsr305.jar, :

javac -d . -classpath ${FINDBUGS_HOME}/lib/annotations.jar:${FINDBUGS_HOME}/lib/jsr305.jar FindBugsAnnotationsTest.java
+2

Source: https://habr.com/ru/post/1715883/


All Articles