Skip to content

Commit

Permalink
SONARKT-388 Fix IllegalArgumentException in CollectionShouldBeImmutab…
Browse files Browse the repository at this point in the history
…leCheck
  • Loading branch information
Godin authored Oct 25, 2024
1 parent 5770f81 commit 3efe09b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,7 @@ class CollectionShouldBeImmutableCheckSample {

private fun nonCompliantParameterOnFileLevel(list: MutableList<Int>): Int { // Noncompliant
return list.reduce { acc, it -> acc + it}
}
}

// https://sonarsource.atlassian.net/browse/SONARKT-388
private fun <T> intersectionType(t: T) = if (t is String) listOf(t) else emptyList()
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ class CollectionShouldBeImmutableCheck : AbstractCheck() {
val functionDescriptor = call.getResolvedCall(bindingContext)?.resultingDescriptor
val parameterTypes = functionDescriptor?.valueParameters
if (parameterTypes != null) {
val fullyQualifiedTypes = parameterTypes.map { it.type.getKotlinTypeFqName(false) }
val fullyQualifiedTypes = parameterTypes.map {
if (it.type.constructor.declarationDescriptor == null) null
else it.type.getKotlinTypeFqName(false)
}
call.valueArguments.zip(fullyQualifiedTypes).filter { it.second in mutableCollections }.map { it.first }
} else {
call.valueArguments
Expand Down

0 comments on commit 3efe09b

Please sign in to comment.