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.
The @NotNull annotation is, actually, an explicit contract declaring that: A method should not return null. Variables (fields, local variables, and parameters) cannot hold a null value.
@NotNull – Checks that the annotated value is not null.
@NotNull validates that the annotated property value is not null. @AssertTrue validates that the annotated property value is true.
Hi, when using the @NotNull annotation, IntelliJ will generate bytecode to throw an IllegalArgumentException when a null is passed/returned.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With