Inspectopedia Help

Redundant array length check

Reports unnecessary array length checks followed by array iteration. When array length is zero, the iteration will be skipped anyway, so there's no need to check length explicitly.

Example:

void f(String[] array) { if (array.length != 0) { // unnecessary check for (String str : array) { System.out.println(str); } } }

A quick-fix is suggested to unwrap or remove the length check:

void f(String[] array) { for (String str : array) { System.out.println(str); } }

New in 2022.3

Inspection Details

By default bundled with:

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin:

Java, 241.14841

Last modified: 12 March 2024