Back to Intellij Community

JavaCollectionsStaticMethodOnImmutableList

plugins/kotlin/code-insight/descriptions/resources-en/inspectionDescriptions/JavaCollectionsStaticMethodOnImmutableList.html

2025.3-rc-2370 B
Original Source

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.