The question Which @NotNull Java annotation should I use? is outdated and somewhat opinion based. Since then Java 8 came, along with newer IDEs.
While Java 8 allows type annotations by integration of JSR 308, it does not come with any. From JSR 308 Explained: Java Type Annotations by Josh Juneau:
JSR 308, Annotations on Java Types, has been incorporated as part of Java SE 8.
...
Compiler checkers can be written to verify annotated code, enforcing rules by generating compiler warnings when code does not meet certain requirements. Java SE 8 does not provide a default type-checking framework, but it is possible to write custom annotations and processors for type checking. There are also a number of type-checking frameworks that can be downloaded, which can be used as plug-ins to the Java compiler to check and enforce types that have been annotated. Type-checking frameworks comprise type annotation definitions and one or more pluggable modules that are used with the compiler for annotation processing.
Considering only solutions that offer at least some kind of @CanBeNull
and @CannotBeNull
, I've found information on the following (could be wrong):
- Eclipse's JDT Null Analysis's
org.eclipse.jdt.annotation
. Other IDEs have their respective packages. Uses JSR 308, and there is still support for pre-Java 8 annotations. - FindBug's
javax.annotation
. Using the dormant JSR 305, it doesn't seem to be using Java 8's type annotations. Even though it's not integrated into Oracle's API, for some reason it still uses thejavax
domain, which implies it does. - Checker Framework's
org.checkerframework.checker.nullness
. Uses JSR 308. - JavaEE's
javax.validation.constraints
. Don't know what it uses, but there is no@CanBeNull
anyways.
Some are used in static code analysis, some in runtime validation.
What are the practical differences between the above options? Is there (going to be) a standard or is it intended for everyone to write their own analysis framework?