Skip to content

Commit 3efe09b

Browse files
authored
SONARKT-388 Fix IllegalArgumentException in CollectionShouldBeImmutableCheck
1 parent 5770f81 commit 3efe09b

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

kotlin-checks-test-sources/src/main/kotlin/checks/CollectionShouldBeImmutableCheckSample.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,7 @@ class CollectionShouldBeImmutableCheckSample {
249249

250250
private fun nonCompliantParameterOnFileLevel(list: MutableList<Int>): Int { // Noncompliant
251251
return list.reduce { acc, it -> acc + it}
252-
}
252+
}
253+
254+
// https://sonarsource.atlassian.net/browse/SONARKT-388
255+
private fun <T> intersectionType(t: T) = if (t is String) listOf(t) else emptyList()

sonar-kotlin-checks/src/main/java/org/sonarsource/kotlin/checks/CollectionShouldBeImmutableCheck.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ class CollectionShouldBeImmutableCheck : AbstractCheck() {
153153
val functionDescriptor = call.getResolvedCall(bindingContext)?.resultingDescriptor
154154
val parameterTypes = functionDescriptor?.valueParameters
155155
if (parameterTypes != null) {
156-
val fullyQualifiedTypes = parameterTypes.map { it.type.getKotlinTypeFqName(false) }
156+
val fullyQualifiedTypes = parameterTypes.map {
157+
if (it.type.constructor.declarationDescriptor == null) null
158+
else it.type.getKotlinTypeFqName(false)
159+
}
157160
call.valueArguments.zip(fullyQualifiedTypes).filter { it.second in mutableCollections }.map { it.first }
158161
} else {
159162
call.valueArguments

0 commit comments

Comments
 (0)