False positive kotlin:S6518 for overloaded set() methods

When an OpenTelemetry function such as LongGauge.set is called like this:

gauge.set(value, attributes)

SonarQube issues an S6518 “defect” reporting that an index operator should be used:

gauge[value] = attributes

This is wrong. The gauge is not a collection, nor a map, and value is not an index. Therefore, SonarQube should not suggest using an indexing operator.

So how should it recognize set functions defined in Java that should not use Kotlin’s indexing syntax? Perhaps S6518 shouldn’t apply when the set function is part of an overloaded set that also takes a different number of arguments (for example, LongGauge has set methods taking 1, 2 or 3 arguments, and SonarQube can thus determine that in the two-argument method the first argument is not a key or an index.

Hey @klitos

Thanks for the report. We already have a ticket in our (unfortunately private) backlog: FP in S6518: avoid reporting on classes not supporting the indexed access operator

I’ve linked this thread to that ticket to help build traction, and so we can come back to you when it’s fixed!

Thank you Colin!