jakartaee/common-annotations-api

Provide two annotations, NonnullField and NonnullApi

Opened this issue · 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

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)

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.