common-annotations-api
common-annotations-api copied to clipboard
Nullness annotations do not reflect the state of the art
Annotations @Nonnull and @Nullable are not specified with the level of detail that would be needed to make this a worthwhile new standard. Since more advanced approaches exist for many years, I suggest to coordinate with those parties having worked in this area.
Some issues with the existing annotations:
- All experts that I talked to agree that nowadays only
TYPE_USEannotations should be used for this purpose, as only those support a degree of annotating the code that will allow analysis tools to give qualified answers. - Even worse, an annotation without any
@Targetmeta annotation will for some corner cases (relating to arrays) affect two locations simultaneously, which makes for a completely obscure pitfall. - It is commonly agreed, that at least one more annotation is needed for practical use: some defaulting annotation, like
@NonNullByDefault
The most pressing issue in this area is the abundance of too many similar annotations. Adding one more set in jakarta only aggravates the problem.
Prior art that should be taken into consideration includes:
- https://checkerframework.org/manual/#nullness-checker by the authors of JSR-308
- Eclipse JDT, talk to me for details. Our approach has been closely coordinated with the Checker Framework people.
- https://jspecify.dev/ -- more recent attempt to standardize
- JetBrains has also worked in this area, but I cannot provide a reference to a contact.