Inspectopedia 2025.3 Help

Conditional expression with negated condition

Reports conditional expressions whose conditions are negated.

Flipping the order of the conditional expression branches usually increases the clarity of such statements.

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

ConditionalExpressionWithNegatedCondition
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Java | Control flow issues

Use the Ignore '!= null' comparisons and Ignore '!= 0' comparisons options to ignore comparisons of the form obj != null or num != 0. Since obj != null effectively means "obj exists", the meaning of the whole expression does not involve any negation and is therefore easy to understand.

The same reasoning applies to num != 0 expressions, especially when using bit masks.

These forms have the added benefit of mentioning the interesting case first. In most cases, the value for the == null branch is null itself, like in the following examples:

static String getName(Person p) { return p != null ? p.getName() : null; } static String getExecutableString(int fileMode) { return (fileMode & 0b001001001) != 0 ? "executable" : "non-executable"; }

Inspection ID: NegatedConditional

Inspection options

Here you can find the description of settings available for the Conditional expression with negated condition inspection, and the reference of their default values.

Ignore '!= null' comparisons

Option ID:

m_ignoreNegatedNullComparison

Default value:

Selected
Ignore '!= 0' comparisons

Option ID:

m_ignoreNegatedZeroComparison

Default value:

Selected

Suppressing Inspection

You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:

//noinspection ConditionalExpressionWithNegatedCondition

More detailed instructions as well as other ways and options that you have can be found in the product documentation:

Inspection Details

By default bundled with:

IntelliJ IDEA 2025.3, Qodana for JVM 2025.3,

Last modified: 03 December 2025