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:
committed by
Mikhail Glukhikh
parent
bec28c8388
commit
7d6cb7805c
Vendored
+10
@@ -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>
|
||||
idea/testData/inspections/javaCollectionsStaticMethodOnImmutableList/inspectionData/inspections.test
Vendored
+2
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user