common-annotations-api icon indicating copy to clipboard operation
common-annotations-api copied to clipboard

Provide two annotations, NonnullField and NonnullApi

Open Silentdoer opened this issue 1 year ago • 2 comments

Like in Spring, non null annotations can be added to all fields in the class and method parameter return values, And it should be able to support annotation of the entire project/module

Silentdoer avatar Nov 21 '23 01:11 Silentdoer

I'd like to see the converse also added NullField and NullApi, this way you could enforce being explicit.

Honestly this is low hanging fruit, I have time on my plate and would be willing to contribute these, as well as any underlying needed duplication of JSR-305 to support them (I notice spring's annotations compose JSR-305 code)

xenoterracide avatar Feb 13 '24 13:02 xenoterracide

Hey, Spring Framework committer here. I am not sure that would be as simple as adding those 2 additional annotations since:

  • Spring use case is leveraging meta annotations
  • The scope where null-safety applies needs to be specified, in JSR 305, we use @TypeQualifierDefault
  • Annotation attributes like When.MAYBE need to be expressed in another way in order to avoid warnings from javac
  • Need to have specifications and tooling support

In a nutshell, going beyond simple @Nonnull and @Nullable annotations is a huge task that is much more involved that it seems, as proven in https://github.com/jspecify/jspecify related work.

sdeleuze avatar Feb 14 '24 10:02 sdeleuze