Inspectopedia 2025.3 Help

Suspicious call on Collection to add or remove Java NIO Path

Reports calls that add or remove a java.nio.file.Path to/from a Kotlin collection or sequence using plus/minus, either in operator form (a + b, a - b) or regular call form (a.plus(b), a.minus(b)).

Since java.nio.file.Path implements Iterable<Path>, such calls resolve to the unexpected overload of the plus or minus function that takes a collection of elements (in this case, the individual elements of the Path). But the intent of the code is probably to add or remove the Path itself, not the individual elements.

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)

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)
  • 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 2025.3, Qodana for JVM 2025.3,

Last modified: 03 December 2025