Looking at my code, I can see tons of fields annotated with
@Nonnull and just a few fields with
@Nullable or without either annotation. This feels wrong.
I'm using @lombok.Nonnull for what it does, @javax.annotation.Nullable as documentation and I'm not very consequent about it. And it's hard to be. The nearly omnipresent @Nonnull adds quite some boilerplate and I'd be more happy if I could leave it out.
So I'm proposing @ForbidNull which can be applied class-wide and makes all fields, method arguments and results @Nonnull, unless annotated by some @Nullable. It could look like
@ForbidNull(fields=boolean, parameters=boolean, results=boolean)
with all three flags defaulting to true (or maybe to what lombok.config says). For me, the most important part are the fields, where nearly all of them are
@Nonnull. I'd like to drop all the annotations and use
@Nullable for the exceptional ones. For the price of a few fail-fast NPEs during development, I could get cleaner and more reliable code.
I know that unlike a checker using @ParametersAreNonnullByDefault, Lombok can't work with inheritance, but that's not that bad. Not dealing with inheritance limits the effect of @ForbidNulls to a single class, so let's call it a feature. It only should know that equals must accept null by a contract inherited from Object.
Any thoughts?