Created
February 5, 2012 19:16
-
-
Save decitrig/1747506 to your computer and use it in GitHub Desktop.
Incorrect FindBugs analysis with CheckForNull annotation on field.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.annotation.CheckForNull; | |
import javax.annotation.Nullable; | |
public class WrongNPWarning { | |
@CheckForNull | |
private String foo; | |
public WrongNPWarning() { | |
Runnable r = new Runnable() { | |
@Override | |
public void run() { | |
if (foo != null) { | |
/* | |
* Getting a findbugs warning on next line: | |
* "Possible null pointer dereference in WrongNPWarning$1.run() due to return value of called method" | |
*/ | |
System.out.println(foo.equals("foo")); | |
} | |
} | |
}; | |
} | |
public void doFoo() { | |
if (foo != null) { | |
// No warning here. | |
System.out.println(foo.equals("foo")); | |
} | |
Runnable r = new Runnable() { | |
@Override | |
public void run() { | |
if (foo != null) { | |
/* | |
* Getting a findbugs warning on next line: | |
* "Possible null pointer dereference in WrongNPWarning$1.run() due to return value of called method" | |
*/ | |
System.out.println(foo.equals("foo")); | |
} | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment