I've been using the @Nonnull and @Nullable annotations on methods to give other programmers (and myself!) a clue about what a method can return. I finally decided to actually run Findbugs on a class (IntelliJ - FindBugs-IDEA v1.0.1), and I don't understand the behavior I'm seeing. The documentation hasn't helped either.
Let's say I have the following example code:
import javax.annotation.Nonnull;
public class Main {
public static void main(String[] args) {
}
@Nonnull
public static String myFunc(){
return new String("foo");
}
@Nonnull
public static String myFunc2(){
return "foo";
}
}
Findbugs flags myFunc()'s return statement as having "Redundant nullcheck of value known to be non-null", but is happy with myFunc2().
Is it expected that findbugs sees these differently? (Link to documentation would be appreciated) Am I completely misunderstanding the use of @Nonnull on methods?
[edit]
After some research, I've decided that the org.jetbrains @Contract annotation (with contract violations changed to errors) will better serve my needs. Thank you Guillaume F. for your help!