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:
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
Pathargument to a collection to clarify intent without changing semantics:For
plus: wrap the argument withtoList()to preserve order.For
minus: wrap the argument withtoSet()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.
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:
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: |