diff --git a/idea/resources/inspectionDescriptions/JavaCollectionsStaticMethodOnImmutableList.html b/idea/resources/inspectionDescriptions/JavaCollectionsStaticMethodOnImmutableList.html index dbd9c3bcf4d..abcf9702ad3 100644 --- a/idea/resources/inspectionDescriptions/JavaCollectionsStaticMethodOnImmutableList.html +++ b/idea/resources/inspectionDescriptions/JavaCollectionsStaticMethodOnImmutableList.html @@ -1,5 +1,6 @@ -This inspection reports immutable Kotlin collection may be changed with Java Collections method. +This inspection report calls of Java mutator methods (like fill, reverse, shuffle, sort) on immutable Kotlin collection. +This will likely produce UnsupportedOperationException at runtime. diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index eab227abff1..e39f0ffe10a 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -2624,11 +2624,11 @@ /> diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/JavaCollectionsStaticMethodOnImmutableListInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/JavaCollectionsStaticMethodOnImmutableListInspection.kt index 0a88d315b68..eeab7fecc5c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/JavaCollectionsStaticMethodOnImmutableListInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/JavaCollectionsStaticMethodOnImmutableListInspection.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.idea.inspections import com.intellij.codeInspection.ProblemsHolder import com.intellij.psi.PsiElementVisitor +import org.jetbrains.kotlin.idea.intentions.callExpression import org.jetbrains.kotlin.psi.dotQualifiedExpressionVisitor class JavaCollectionsStaticMethodOnImmutableListInspection : AbstractKotlinInspection() { @@ -14,8 +15,8 @@ class JavaCollectionsStaticMethodOnImmutableListInspection : AbstractKotlinInspe return dotQualifiedExpressionVisitor(fun(expression) { val (methodName, firstArg) = JavaCollectionsStaticMethodInspection.getTargetMethodOnImmutableList(expression) ?: return holder.registerProblem( - expression, - "The '${firstArg.text}' may be changed with Java Collections method '$methodName'" + expression.callExpression?.calleeExpression ?: expression, + "Call of Java mutator '$methodName' on immutable Kotlin collection '${firstArg.text}'" ) }) } diff --git a/idea/testData/inspections/javaCollectionsStaticMethodOnImmutableList/inspectionData/expected.xml b/idea/testData/inspections/javaCollectionsStaticMethodOnImmutableList/inspectionData/expected.xml index aa1f0b7975e..d073fd8817f 100644 --- a/idea/testData/inspections/javaCollectionsStaticMethodOnImmutableList/inspectionData/expected.xml +++ b/idea/testData/inspections/javaCollectionsStaticMethodOnImmutableList/inspectionData/expected.xml @@ -4,7 +4,7 @@ 5 light_idea_test_case - Immutable Kotlin collection may be changed with Java Collections method - The 'immutableList' may be changed with Java Collections method 'reverse' + Call of Java mutator method on immutable Kotlin collection + Call of Java mutator 'reverse' on immutable Kotlin collection 'immutableList'