What is the best 'NonNull' annotation?
"Best" in the sense of
- Standard way e.g. future proofness (e.g. support by standard jdk etc.)
- Support of IDE's (shows up in java doc to indicate the usage for developers)
- Support by static analysis tools like findbugs
- Support for runtime analysis
Here's how the world currently look like - any further insight is appreciated:
javax.validation.constraints.NotNull
(Docs)
+ javax package thus seems futureproof
- Part of JEE not JSE. In JSE need to import additional libs.
- Not supported by static analysis tools (runtime validation only)(docs)edu.umd.cs.findbugs.annotations.NonNull
- external library and not anjavax
package
- deprecated since findbugs version 3.X
+ used for static analysis (by findbugs and therefore Sonar)(docs)javax.annotation.Nonnull
+ used for static analysis (in findbugs)
- JSR-305 is dormant/dead/unknown as on the fb mailing list indicated. The author Bill Pugh, even if directly asked, hasn't commented the state in years...(docs, interesting presentation)org.eclipse.jdt.annotation_2.0.0
+ used for static analysis (in eclipse not in findbugs though)
- proprietary to eclipse (didn't try to use them standalone)(docs)org.jetbrains.annotations.NotNull
+ used for static analysis (in intelliJ not in findbugs though)
- proprietary to IntelliJ (but also publicly available as a jar)lombok.NonNull
(docs)
+ used to control code generation
- proprietary annotationandroid.support.annotation.NonNull
(docs)
+ static analysis in android studio
- android specific proprietary annotationorg.checkerframework.checker.nullness.qual.NonNull
(docs)
+ JSR308 implementation which is part of Java8 (which did introduce the ability to write annotations in different parts of your code, but did not introduce new annotations)
+ used for static code (not findbugs though) and runtime analysis
- external lib however seems to be endorsed by the java folks
Currently I would tend to the Checker Framework but I am looking forward for other views...
[disclaimer] I know the question has been asked here however was not answered (or the answer was wrong/incomplete/outdated) [/disclaimer]