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.