Repository: detekt/detekt (kotlin)

Issue:
False positive of ExplicitCollectionElementAccessMethod on ListOrderedMap
This is detekt 1.23.6. In `org.apache.commons.collections4.map.ListOrderedMap` there exist an API [`put(index, key, value)`](https://commons.apache.org/proper/commons-collections/apidocs/org/apache/commons/collections4/map/ListOrderedMap.html#put(int,K,V)) that Detekt falsely claims to be replacable with an index operator:

```
list.put(0, newVehicleKey, ArrayList<ScanItem>())
```

Error:

```
MyFile.kt:280:13: Prefer usage of the indexed access operator [] for map element access or insert methods. [ExplicitCollectionElementAccessMethod]
```

Pull request description:
Fixes #7562

Patch:
diff --git a/detekt-rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/ExplicitCollectionElementAccessMethod.kt b/detekt-rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/ExplicitCollectionElementAccessMethod.kt
index f4f7a9f151dd..95ce774b9aca 100644
--- a/detekt-rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/ExplicitCollectionElementAccessMethod.kt
+++ b/detekt-rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/ExplicitCollectionElementAccessMethod.kt
@@ -105,6 +105,7 @@ class ExplicitCollectionElementAccessMethod(config: Config) : Rule(
     }
 
     private fun isCallerMap(expression: KtCallExpression): Boolean {
+        if (expression.valueArguments.size != 2) return false
         val caller = expression.getQualifiedExpressionForSelector()?.receiverExpression
         val type = caller.getResolvedCall(bindingContext)?.resultingDescriptor?.returnType
         if (type == null || type is ErrorType) return false // There is no caller or it can't be resolved.


Test patch:
diff --git a/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/ExplicitCollectionElementAccessMethodSpec.kt b/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/ExplicitCollectionElementAccessMethodSpec.kt
index eb3ae61db927..ff8645f41b7f 100644
--- a/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/ExplicitCollectionElementAccessMethodSpec.kt
+++ b/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/ExplicitCollectionElementAccessMethodSpec.kt
@@ -74,6 +74,22 @@ class ExplicitCollectionElementAccessMethodSpec {
                 assertThat(subject.compileAndLintWithContext(env, code)).isEmpty()
             }
 
+            @Test
+            fun `does not report map put method usage with three arguments`() {
+                val code = """
+                    class MyMap : java.util.HashMap<String, Int>() {
+                        fun put(key: String, key2: String, value: Int): Int {
+                            return value
+                        }
+                    }
+                    fun main() {
+                        val map = MyMap()
+                        map.put("a", "b", 1)
+                    }
+                """.trimIndent()
+                assertThat(subject.compileAndLintWithContext(env, code)).isEmpty()
+            }
+
             @Test
             fun `does not report map put method with used return value`() {
                 val code = """