Inspectopedia 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); } }

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

Option

Type

Default

Ignore '!= null' comparisons

Checkbox

true

Ignore '!= 0' comparisons

Checkbox

false

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3

Plugin:

Java, 233.SNAPSHOT

Last modified: 13 July 2023