UnnecessaryCheckNotNull
This null check is unnecessary; the expression can never be null

Severity
ERROR

Alternate names: PreconditionsCheckNotNull, PreconditionsCheckNotNullPrimitive

The problem

There are various libraries available to check if a variable is null or not. Most notable ones are :

These methods generally takes two arguments. The first is the reference that should be non-null. The second is the error message to print (usually a string literal).

There are some common scenarios where the first argument can’t be null but is still checked to be null and is thus redundant.

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("UnnecessaryCheckNotNull") to the enclosing element.