Call of Java mutator method on immutable Kotlin collection
Reports Java mutator methods calls (like fill
, reverse
, shuffle
, sort
) on an immutable Kotlin collection.
This can lead to UnsupportedOperationException
at runtime.
Example:
import java.util.Collections
fun test() {
val immutableList = listOf(1, 2)
Collections.reverse(immutableList)
}
To fix the problem make the list mutable.
Inspection Details | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Kotlin, @snapshot@ |
Last modified: 13 July 2023