Add inspection: Java mutator method used on immutable Kotlin Collections

In particular, fill, reverse, shuffle, sort calls are reported
So #KT-22011 Fixed
This commit is contained in:
Toshiaki Kameyama
2018-02-19 09:56:28 +03:00
committed by Mikhail Glukhikh
parent bec28c8388
commit 7d6cb7805c
8 changed files with 113 additions and 27 deletions
@@ -0,0 +1,10 @@
<problems>
<problem>
<file>test.kt</file>
<line>5</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="test.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Immutable Kotlin collection may be changed with Java Collections method</problem_class>
<description>The 'immutableList' may be changed with Java Collections method 'reverse'</description>
</problem>
</problems>
@@ -0,0 +1,2 @@
// INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.JavaCollectionsStaticMethodOnImmutableListInspection
// RUNTIME_WITH_FULL_JDK
@@ -0,0 +1,9 @@
import java.util.Collections
fun test() {
val immutableList = listOf(1, 2)
Collections.reverse(immutableList)
val mutableList = mutableListOf(1)
Collections.reverse(mutableList)
}