dotty icon indicating copy to clipboard operation
dotty copied to clipboard

Use Checkers Framework annotations for common libraries

Open abeln opened this issue 7 years ago • 1 comments

@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:

  1. https://checkerframework.org/annotation-file-utilities/
  2. https://checkerframework.org/annotation-file-utilities/annotation-file-format.html
  3. 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.

abeln avatar Sep 24 '18 10:09 abeln

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.

liufengyun avatar Sep 24 '18 11:09 liufengyun