Inspectopedia Help

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.


import java.util.Collections fun test() { val immutableList = listOf(1, 2) Collections.reverse(immutableList) }

To fix the problem make the list mutable.

Inspection Details

By default bundled with:

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin:

Kotlin, 241.14841-IJ

Last modified: 12 March 2024