Reputation: 35792
It seems like there are quite a few different annotations to indicate the nullability status of method parameters and return values in Java, and the situation has been evolving.
What are best practices in 2013 for annotating my methods for nullability?
I'm aware of this question, but it is from 3 years ago and I suspect the situation has changed since then:
Which @NotNull Java annotation should I use?
I personally use IntelliJ IDEA, but would hope for a solution that doesn't tie my project to that IDE. I use Maven for dependency management.
Upvotes: 14
Views: 2154
Reputation: 49095
The reason there are so many is there is a difference between defensive programming and input validation.
@NotNull is the java bean validation framework JSR 303. @Nullable is the JSR 305 which is for defensive programming / design by contract.
Find bugs guava one is the defacto JSR 305. Hibernate offers pretty much defacto JSR 303.
Upvotes: 1
Reputation: 692181
AFAIK, the almost standard library is com.google.code.findbugs:jsr305. It's the one used by Guava, for example. And it's supported by FindBugs, which is probably the most used byte-code analysis tool.
IntelliJ supports those annotations as well.
Upvotes: 4