I use @Nonnull and @Nullable method annotations to give other programmers (and me!) A hint about what the method can return. Finally, I decided to actually run Findbugs in the class (IntelliJ - FindBugs-IDEA v1.0.1), and I do not understand the behavior that I see. The documentation also did not help.
Let's say I have the following code example:
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 () returns the statement as having a "redundant nullcheck value that is not known to be null", but is happy with myFunc2 ().
Are findbugs expected to see this differently? (A link to the documentation would be appreciated) Am I completely misunderstanding the use of @Nonnull in methods?
[edit]
After some research, I decided that the org.jetbrains @Contract annotation (with a contract change to bugs) would better satisfy my needs. Thanks Guillaume F. for your help!
java findbugs
KathyA.
source share