Inspectopedia 2025.2 Help

'if' statement with negated condition

Reports if statements that contain else branches and whose conditions are negated.

Flipping the order of the if and else branches usually increases the clarity of such statements.

There is a fix that inverts the current if statement.

Example:

void m(Object o1, Object o2) { if (o1 != o2) { System.out.println(1); } else { System.out.println(2); } }

After applying the quick-fix:

void m(Object o1, Object o2) { if (o1 == o2) { System.out.println(2); } else { System.out.println(1); } }

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.

IfStatementWithNegatedCondition
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 option to ignore comparisons of the != null form.

Use the Ignore '!= 0' comparisons option to ignore comparisons of the != 0 form.

Inspection options

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

Ignore '!= null' comparisons

Default value:

Selected
Ignore '!= 0' comparisons

Default value:

Not 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 IfStatementWithNegatedCondition

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.2, Qodana for JVM 2025.2,

Last modified: 18 September 2025