Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the situation in 2013 with @notnull annotations in Java?

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.

like image 475
sanity Avatar asked Jun 08 '13 21:06

sanity


People also ask

What happens when you annotate a field with @NotNull in Java?

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.

What is the use of @NotNull annotation in spring boot?

@NotNull – Checks that the annotated value is not null.

What does @NotNull annotation Bean in Bean property?

@NotNull validates that the annotated property value is not null. @AssertTrue validates that the annotated property value is true.

What exception does @NotNull throw?

Hi, when using the @NotNull annotation, IntelliJ will generate bytecode to throw an IllegalArgumentException when a null is passed/returned.


1 Answers

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.

like image 113
JB Nizet Avatar answered Oct 04 '22 04:10

JB Nizet