Inspectopedia Help

Redundant operation on empty container

Reports redundant operations on empty collections, maps or arrays.

Iterating, removing elements, sorting, and some other operations on empty collections have no effect and can be removed. Also, they may be a signal of a bug.

Example:

if (numbers.isEmpty()){ //error due to the missed negation int max = numbers.stream().max(Comparator.naturalOrder()).get(); ... }

New in 2019.1

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