Note that there are some explanatory texts on larger screens.

plurals
  1. POWhich @NotNull Java annotation should I use?
    primarykey
    data
    text
    <p>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' <code>@NotNull</code>/<code>@NonNull</code>/<code>@Nonnull</code> 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:</p> <ul> <li><p><strong><code>javax.validation.constraints.NotNull</code></strong><br> <em>Created for runtime validation, not static analysis.</em><br> <a href="http://download.oracle.com/javaee/6/api/javax/validation/constraints/NotNull.html" rel="noreferrer">documentation</a></p></li> <li><p><strong><code>edu.umd.cs.findbugs.annotations.NonNull</code></strong><br> <em>Used by <a href="http://findbugs.sourceforge.net/" rel="noreferrer">Findbugs</a> static analysis and therefore Sonar (now <a href="https://www.sonarqube.org/" rel="noreferrer">Sonarqube</a>)</em><br> <a href="http://findbugs.sourceforge.net/manual/annotations.html" rel="noreferrer">documentation</a></p></li> <li><p><strong><code>javax.annotation.Nonnull</code></strong><br> <em>This might work with Findbugs too, but <a href="https://jcp.org/en/jsr/detail?id=305" rel="noreferrer">JSR-305</a> is inactive. (See also: <a href="https://stackoverflow.com/questions/2289694/what-is-the-status-of-jsr-305">What is the status of JSR 305?</a>)</em> <a href="http://code.google.com/p/jsr-305/source/browse/trunk/ri/src/main/java/javax/annotation/Nonnull.java" rel="noreferrer">source</a></p></li> <li><p><strong><code>org.jetbrains.annotations.NotNull</code></strong><br> <em>Used by IntelliJ IDEA IDE for static analysis.</em><br> <a href="https://www.jetbrains.com/help/idea/nullable-and-notnull-annotations.html" rel="noreferrer">documentation</a></p></li> <li><p><strong><code>lombok.NonNull</code></strong><br> <em>Used to control code generation in <a href="https://projectlombok.org/" rel="noreferrer">Project Lombok</a>.</em><br> <em>Placeholder annotation since there is no standard.</em><br> <a href="https://github.com/rzwitserloot/lombok/blob/master/src/core/lombok/NonNull.java" rel="noreferrer">source</a>, <a href="https://projectlombok.org/features/NonNull.html" rel="noreferrer">documentation</a></p></li> <li><p><strong><code>android.support.annotation.NonNull</code></strong><br> <em>Marker annotation available in Android, provided by support-annotations package</em><br> <a href="https://developer.android.com/reference/android/support/annotation/NonNull.html" rel="noreferrer">documentation</a></p></li> <li><p><strong><code>org.eclipse.jdt.annotation.NonNull</code></strong><br> <em>Used by Eclipse for static code analysis</em><br> <a href="http://help.eclipse.org/oxygen/topic/org.eclipse.jdt.doc.user/tasks/task-improve_code_quality.htm" rel="noreferrer">documentation</a></p></li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload