NullTernary
This conditional expression may evaluate to null, which will result in an NPE when the result is unboxed.

Category
Severity
ERROR
Maturity

The problem

If a conditional expression evalutes to null, unboxing it will result in a NullPointerException.

For example:

int x = flag ? foo : null:

If flag is false, null will be auto-unboxed from an Integer to int, resulting in a NullPointerException.

Suppression

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