Skip to content

Instantly share code, notes, and snippets.

@decitrig
Created February 5, 2012 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save decitrig/1747506 to your computer and use it in GitHub Desktop.
Save decitrig/1747506 to your computer and use it in GitHub Desktop.
Incorrect FindBugs analysis with CheckForNull annotation on field.
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