Use Checkers Framework annotations for common libraries
@liufengyun writes
Currently, there are 3 well-known NonNull annotations in the Java world:
- JSR 305 : javax.annotation.Nonnull
- Android: @NonNull
- CheckerFramework: @NonNull
A quick github search suggests that Android @NonNull seems to be widely adopted among Android developers.
Kotlin currently supports all known annotations (source):
JetBrains (@Nullable and @NotNull from the org.jetbrains.annotations package)
Android (com.android.annotations and android.support.annotations)
JSR-305 (javax.annotation)
CheckerFramework
FindBugs (edu.umd.cs.findbugs.annotations)
Eclipse (org.eclipse.jdt.annotation)
Lombok (lombok.NonNull).
If the Java source code has no @NonNull annotations, e.g. JDK, can we do better?
Yes. CheckerFramework recently published standard format about external annotation database (.jaif), on August 30th, 2018:
- https://checkerframework.org/annotation-file-utilities/
- https://checkerframework.org/annotation-file-utilities/annotation-file-format.html
- https://github.com/typetools/annotated-libraries
A natural step is to (1) use CheckerFramework inference tools automatically generate annotation databases for Java libraries; (2) grow the databases via crowdsourcing (a more friendly DB interface required). This can be useful for JDK and widely used libraries like Guava, as the APIs are very stable.
I don't know how well CheckerFramework performs in nullness annotation inference, they do have the feature:
https://checkerframework.org/manual/#nullness-inference
It would be cool if it can generate a useful set of @NonNull annotations for JDK.