forum

Home / DeveloperSection / Forums / Which @NotNull Java annotation should I use?

Which @NotNull Java annotation should I use?

Anonymous User219317-Jul-2015
I'm looking to make my code more readable as well as use tooling like IDE code inspection and/or static code analysis (FindBugs and Sonar) to avoid NullPointerExceptions. Many of the tools seem incompatible with each others' @NotNull/@NonNull/@Nonnull annotation and listing all of them in my code would be terrible to read. Any suggestions of which one is the 'best'? Here is the list of equivalent annotations I've found:

javax.validation.constraints.NotNull
Created for runtime validation, not static analysis.
documentation

edu.umd.cs.findbugs.annotations.NonNull
Used by Findbugs static analysis and therefore Sonar
documentation

javax.annotation.Nonnull
This might work with Findbugs too, but JSR-305 is inactive.
source

com.intellij.annotations.NotNull
Used by IntelliJ IDEA IDE for static analysis.
documentation

lombok.NonNull
Used to control code generation in Project Lombok.

Updated on 18-Jul-2015
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By