Inspectopedia 2026.2 Help

Suspicious call to add or remove Iterable argument

Reports usages of `plus`/`minus` where the argument type implements `Iterable`, and the receiver is a Kotlin `Collection` or `Sequence` of the same element type.

If the argument type implements `Iterable`, it is treated as a collection of elements rather than as a single element. This may unintentionally add or remove multiple elements instead of the object itself.

A common example is `java.nio.file.Path`, which implements `Iterable<Path>` (iterating over its name elements). Adding a `Path` to a `Collection<Path>` using `+` or `-` may therefore operate on its components rather than on the `Path` instance as a whole.

The inspection covers both operator syntax (`a + b`, `a - b`) and explicit calls (`a.plus(b)`, `a.minus(b)`).

Examples:

// Operator form val paths = listOf(path) + somePath val paths2 = setOf(path) - somePath // Regular call form val paths = listOf(path).plus(somePath) val paths2 = setOf(path).minus(somePath) // Sequences val seq = sequenceOf(path) + somePath // Path + Path (both sides are iterable) val combined = path1 + path2 // Returns List of segments, not a combined path

Quick-fixes:

  • Convert to plusElement/minusElement (changes the semantics to what was originally intended):

    val paths = listOf(path).plusElement(somePath) val paths2 = setOf(path).minusElement(somePath) val paths3 = sequenceOf(path).plusElement(somePath)
  • Convert the Path argument to a collection to clarify intent without changing semantics:

    • For plus: wrap the argument with toList() to preserve order.

    • For minus: wrap the argument with toSet() for efficient removal.

    val paths = listOf(path).plus(somePath.toList()) val paths2 = setOf(path).minus(somePath.toSet())

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.

SuspiciousCallOnCollectionToAddOrRemovePath
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 | Kotlin | Probable bugs

Inspection ID: SuspiciousCallOnCollectionToAddOrRemovePath

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 SuspiciousCallOnCollectionToAddOrRemovePath

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 2026.2, Qodana for JVM 2026.2,

Last modified: 30 June 2026